ZEND, Change form

I have a Zend form to add something to the database. And then I want to use this form to edit what I added to the databese. Is it possible to use this form (fill it out from the database and display it?) I have this in the controller:

public function editAction() {

    if (Zend_Auth::getInstance()->hasIdentity()) {
        try {
            $form = new Application_Form_NewStory();
            $request = $this->getRequest();
            $story = new Application_Model_DbTable_Story();
            $result = $story->find($request->getParam('id'));

           // $values = array(
           //     'title' => $result->title,
           //     'story' => $result->story,
           // );

            if ($this->getRequest()->isPost()) {
                if ($form->isValid($request->getPost())) {
                    $data = array(
                        'title' => $form->getValue("title"),
                        'story' => $form->getValue("story"),
                    );
                    $where = array(
                        'id' => $request->getParam('id'),
                    );
                    $story->update($data, $where);
                }
            }
            $this->view->form = $form;
            $this->view->titleS= $result->title;
            $this->view->storyS= $result->story;
        } catch (Exception $e) {
            echo $e;
        }
    } else {
        $this->_helper->redirector->goToRoute(array(
            'controller' => 'auth',
            'action' => 'index'
        ));
    }
}

In my opinion:

<?php
try
{
$tmp = $this->form->setAction($this->url());
//$tmp->titleS=$this->title;
//$tmp->storyS=$this->story;

//echo $tmp->title = "aaaaa";
}
catch(Exception $e)
{
    echo $e;
}

And when I try to change something in this view, I mean giving any value other than NULL. I have a mistake that I cannot make, so is there any way to reuse this form? Or not?

Thank!

+5
source share
1 answer

Zend_Form populate(), . :

$form->populate($result->current()->toArray());

.

+11

All Articles