我正在尝试使用锂框架 (0.10) 编写编辑表单。我使用 MySQL 作为 DBMS。 Controller 看起来像这样:
public function edit() {
$success = false;
$data = Posts::find(42);
return compact('data');
}
查看文件:
<?=$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; ?>
调用站点时收到此错误消息:
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
我做错了什么?在锂中构建编辑表单的正确方法是什么?不幸的是,official lithium docs 中没有这方面的信息。 .
最佳答案
您想将数据传递给表单。这样就变成了
<?=$this->form->create($data); ?>
可以看看http://li3.me/docs/manual/quickstart几个月前我一直在玩。希望这也适用于最新版本。
关于php - 如何使用锂框架构建编辑表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7065606/