php - Select element from other table on the form zf2 -


i have 2 table manytoone relation on database between client , sale , want select id_client on sale form . o used .

saleform :

public function __construct(clienttable $table)     {         parent::__construct('vente');          $this->setattribute('method', 'post');         $this->clienttable = $table;              $this->add(array(             'name' => 'id',             'attributes' => array(                 'type'  => 'hidden',             ),         ));         $this->add(                 array(                     'name' => 'id_client',                     'type' => 'select',                     'attributes' => array(                         'id'    => 'id_client'                     ),                     'options' => array(                         'label' => 'catégory',                         'value_options' => $this->getclientoptions(),                         'empty_option'  => '--- sélectionnez une categorie---'                     ),                 )             );          public function getclientoptions()         {             $data  = $this->clienttable->fetchall()->toarray();             $selectdata = array();              foreach ($data $key => $selectoption) {                 $selectdata[$selectoption["id"]] = $selectoption["nom_client"];             }              return $selectdata;         } } 

salecontroller:

use zend\mvc\controller\abstractactioncontroller; use zend\view\model\viewmodel; use caisse\model\sale;           use caisse\form\saleform;   class salecontroller extends abstractactioncontroller {     protected $saletable;     protected $clienttable;      public function addaction()     {         $form = new saleform($this->clienttable);         $form->get('submit')->setvalue('ajouter');          $request = $this->getrequest();         if ($request->ispost()) {             $vente = new sale();             $form->setinputfilter($sale->getinputfilter());             $form->setdata($request->getpost());              if ($form->isvalid()) {                 $vente->exchangearray($form->getdata());                 $this->getsaletable()->savesale($sale);                   return $this->redirect()->toroute('sale');             }         }         return array('form' => $form);      } } 

but every time had issue:

catchable fatal error: argument 1 passed caisse\form\saleform::__construct() must instance of admin\model\clienttable, null given.

is method it, reference same example welcome.

thank you

inside controller, function addaction, never set variable clienttable maybe forgot initialize it.

like this

public function addaction() {     $this->clienttable = $this->getservicelocator()->get('client\model\clienttable');     $form = new saleform($this->clienttable);     // ... } 

about

    public function getclientoptions()     {         $data  = $this->clienttable->fetchall();         $selectdata = array();          foreach ($data $row) {             $selectdata[$row->id] = $row->nom_client;         }          return $selectdata;     } 

Comments

  1. Wonderfully explained. Test Automation Framework is an automated software testing tool that makes it easy for you to create, deploy, and manage your automated tests. Eiliana.com is a freelancing platform that provides a safe environment where you can get quality services from reliable professionals at affordable prices. Sign up today.

    ReplyDelete

Post a Comment

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -