[英]How to build a edit form with the lithium framework
I'm trying to write a edit form with the lithium framework (0.10).我正在尝试使用锂框架(0.10)编写一个编辑表单。 I'm using MySQL as the DBMS.
我使用 MySQL 作为 DBMS。 The controller looks like this:
controller 看起来像这样:
public function edit() {
$success = false;
$data = Posts::find(42);
return compact('data');
}
The view file:视图文件:
<?=$this->form->create(); ?>
<?=$this->form->field('title');?>
<?=$this->form->field('body', array('type' => 'textarea'));?>
<?=$this->form->submit('Add Post'); ?>
<?=$this->form->end(); ?>
<?php if ($success): ?>
<p style="color: red;">Post Successfully Saved</p>
<?php endif; ?>
When calling the site a get this error message:调用站点时收到此错误消息:
Fatal error: Cannot use object of type lithium\data\entity\Record as array in /var/www/web/frameworks/lithium-0.10/app/resources/tmp/cache/templates/template_views_posts_edit.html_483_1313415231_358.php on line 2
What am I doing wrong?我究竟做错了什么? Whats the right way to build a edit form in lithium?
在锂中构建编辑表单的正确方法是什么? Unfortunately, there is no information on this in the official lithium docs .
不幸的是,官方锂文档中没有这方面的信息。
You want to pass the data to form.您想将数据传递给表单。 So that will become
所以这将成为
<?=$this->form->create($data); ?>
You can look http://li3.me/docs/manual/quickstart which I have been playing some months back.您可以查看几个月前我一直在玩的http://li3.me/docs/manual/quickstart 。 Hope this will work with the latest also.
希望这也适用于最新版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.