Controller Code generated doesn't seem ok

Hello,

I used the Developer Tools latest version to generate Controller code for a class. It doesn't seem to be ok and doesn't work properly. I would like to understand the logic. Here is the default starting code generated of create action of a class.

    public function createAction()
    {

        if (!$this->request->isPost()) {
            return $this->dispatcher->forward(array(
                "controller" => "ro_relorder_t",
                "action" => "index"
            ));
        }

        $ro_relorder_t = new RoRelorderT();
        ...

This takes me to index page every time I try to create a new record. I have a create.volt (equivalent of new). With above code in place it never executes. The same code exists in edit action also. The code in Vokuro example with forms is different. That seems to work fine after customization.

    public function createAction()
    {
        if ($this->request->isPost()) {

            $ro_relorder_t = new RoRelorderT();
            ...

Can't I use the code generated by Developer Tools directly.

Regards, Amal

edited Apr '15
public function createAction()
{

  // comment the following three lines if you have already registered the di component
      $di = new Phalcon\DI();
      $dispatcher = new Phalcon\Mvc\Dispatcher();
      $dispatcher->setDI($di);

      if (!$this->request->isPost()) {

          $this->dispatcher->forward(array('controller' => 'ro_relorder_t', 'action' => 'index'));

          // if the above live don't work try to comment and uncomment the following line

          // $this->response->redirect('ro_relorder_t');

      }else{
          $ro_relorder_t = new RoRelorderT();
      }

    }


6.4k

@Dominic,

My question was incorrectly phrased, I edited it to correct it. The code you wrote is very similar to what the Developer Tools generate. There could be in issue with my understanding. Shouldn't we execute code from createAction if it is NOT Post action. In other words, is it that if we are not in Post processing we should redirect to index and instantiate the Form (record entry screen) in the index page. I thought I should instantiate the Form in createAction.

Amal