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 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. Hope this will work with the latest also.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top