2

我正在尝试使用锂框架(0.10)编写一个编辑表单。我使用 MySQL 作为 DBMS。控制器如下所示:

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

我究竟做错了什么?在锂中构建编辑表单的正确方法是什么?不幸的是,官方锂文档中没有这方面的信息。

4

1 回答 1

1

您想将数据传递给表单。所以这将成为

<?=$this->form->create($data); ?>

您可以查看几个月前我一直在玩的http://li3.me/docs/manual/quickstart 。希望这也适用于最新版本。

于 2011-08-15T13:51:14.120 回答