2

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.

botero
  • 598
  • 2
  • 11
  • 23
wowpatrick
  • 5,082
  • 15
  • 55
  • 86

1 Answers1

1

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.

botero
  • 598
  • 2
  • 11
  • 23
Hari K T
  • 4,174
  • 3
  • 32
  • 51
  • Thanks for your answer! Just one more question, what is the method I have to use to save the changed data? ATM I've got `if($this->request->data) { $post = Posts::update($this->request->data); $success = $post->save(); }` – wowpatrick Aug 15 '11 at 18:50
  • As you can see in http://dev.lithify.me/forks/harikt/lithium_blog, first I get the object `$user = User::find($this->request->id);` if not redirect else do the save on it via `$user->save($this->request->data)` . – Hari K T Aug 16 '11 at 08:14