开发者

How to build a edit form with the lithium framework

I'm trying to write a edit form with the lithium framework (0.10). I'm using MySQL as the DBMS. The controller looks like this:

public function edit() {
    $success = false;

    $data = Posts::find(42);

    return compa开发者_Go百科ct('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. Hope this will work with the latest also.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜