PHP / Zend Framework 2 / CRUD - How to structure controller for several actions, several views? -


preface

i working on web application have been adapting existing asp.net web forms app had written previously. of logic app in end code behind.

following creation of application , desire change app technology using mvc, decided use php/zend framework 2 develop understanding of mvc , php can make code more structured.

what have done far...

i have details form can create new record, (i.e. create part of crud).

so far view folder looks this

 view    |    --action-item        |        --details        |    |        |    --index.phtml    <--single view template handle crud        |        --summary             |             --index.phtml    <--separate view not related details 

desired route template

  localhost/actionitem/create             <-- c (create new record)   localhost/actionitem/view/1             <-- r (read first element)   localhost/actionitem/update/1           <-- u (update first element)   localhost/actionitem/delete/1           <-- d (delete first element) 

controller action methods

/* @var $actionitemtable actionitemtable */     public function summaryaction()     {         return new viewmodel(array(             'actionitems' => $this->getactionitemtable()->fetchall(),         ));            }      public function detailsaction()     {         $dbadapter = $this->getservicelocator()->get('zend\db\adapter\adapter');         $form = new \application\form\actionitemform($dbadapter);         return ['form' => $form];     }      public function createaction()     {         $dbadapter = $this->getservicelocator()->get('zend\db\adapter\adapter');         $form = new \application\form\actionitemform($dbadapter);          $request = $this->getrequest();         if($request->ispost())         {             $request = $this->getrequest();             $actionitem = new actionitem();              if($request->ispost())             {                                $form->setdata($request->getpost());                 if ($form->isvalid())                 {                     $actionitem->exchangearray($form->getdata());                     $this->getactionitemtable()->saveactionitem($actionitem);                 }             }         }          return ['form' => $form];     } 

question

what appropriate way structure actions handle crud operations, , idea divide controller separate controllers?

any or suggestions appreciated...

maybe should think going restful approach.

zf2 has abstractrestfulcontroller class this. using controller can map create, read update , delete actions respective post, get, put/patch , delete http methods.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -