How to access the model from the controller in zend? -


this controller

class locationcontroller  {      .....       public function testareaction(){          $this->_helper->layout->disablelayout();         $this->_helper->viewrenderer->setnorender(true);         $myarray =  $_post['data_post'];         $product_ids = $_post['product_ids'];         echo "test1";         $model = new application_model_ordernames();          echo "test2";         $model -> saveordernames();      } } 

and model :

<?php     class ordernames {         public function __construct(){          }         public function saveordernames(){             return 1;         }      }    ?>  

what im doing wrong ? why cannot access "test2" string in browser? thx

this full controller class :

<?php  use application\model\cronos,     application\model\dbtable;  class locationcontroller extends \lunchbox\controller {     public function indexaction()     {         if (!($locationurl = $this->_getparam('locationurl'))) {             throw new \zend_controller_action_exception('location url not provided.', 404);         }                  $this->maidivclass = "block clear step1";          // location row         $mapper = new dbtable\location();         $sql = $mapper->select()->where('url = ?', $locationurl);          if (!($this->view->location = $mapper->fetchrowactive($sql))) {             throw new \zend_controller_action_exception('location not found', 404);         }          // set active markup location menu         $this->_helper->layout()->locationmainmenuurl = $this->view->location->url;          // seo         $this->setseo(             $this->view->location->meta_title,              $this->view->location->meta_description,              $this->view->location->meta_keywords         );          // day param         $dayname = $this->_getparam('day', cronos::getcurrentdayname());          $this->view->dayno = cronos::getweekdaynumber($dayname);         if ($this->view->dayno === false) {             throw new \zend_controller_action_exception('invalid weekday provided.', 404);         }          $this->view->selecteddate = cronos::getdatewithoffset($this->view->dayno); // date offset         $this->view->categmapper  = new dbtable\categories();          $appcfg = new zend_config_ini(application_path . '/configs/application.ini', application_env);         $this->view->s3 = "http://".$appcfg->custom->s3->bucket;         $imgmapper = new application_model_mapper_images();         $this->view->imgs = $imgmapper->fetchallbylocationid($this->view->location->id);           /**          * show products allowed admin emails. testing only.          * admin must logged in see products, while test on.          *           * disable, change custom.test.isenabled flag in app.ini.          */         $testcfg = zend_registry::get('zend_config')->custom->test->toarray();         $isenabled = (bool) $testcfg['isenabled'];          // test enabled?         if ($isenabled) {             $email = false;              $auth  = zend_auth::getinstance();             // grab email, if logged in             if ($auth->hasidentity()) { $email = $auth->getidentity()->email; }              // has email? check against config, else don't show products             $showproducts = ($email) ? in_array($email, (array) $testcfg['email']) : false;          // test disabled: show products         } else {             $showproducts = true;         }          if ($showproducts) {              // categories & products date , location             $prodservice = new \application\service\products();             $this->view->categswithprods = $prodservice->getproducts($this->view->location->id, $this->view->selecteddate);               //check days of week products             $week = array();             $currentday = cronos::getweekdaynumberbydate();             if($this->view->location->erp_name != "city lbox") {                 for($day=$currentday;$day<7;$day++)                 {                     $selecteddate = cronos::getdatewithoffset($day);                     $categswithprod = $prodservice->getproducts($this->view->location->id, $selecteddate);                     if(count($categswithprod))                         $week[] = $day;                  }                 //we need go sunday , next week                 for($day=0;$day<$currentday;$day++)                 {                     $selecteddate = cronos::getdatewithoffset($day);                     $categswithprod = $prodservice->getproducts($this->view->location->id, $selecteddate);                     if(count($categswithprod))                         $week[] = $day;                 }              } else {                 for($day = $currentday; $day<7;$day++) {                     $week[] = $day;                 }                 for($day = 0; $day<$currentday; $day++) {                     $week[] = $day;                 }             }              $this->view->week = $week;             $specialmenurows = $this->view->location->getspecialmenus(new zend_date());             $this->view->specialmenus = $this->view->partial('_partials/specialmenu.phtml', array('specialmenus' => $specialmenurows));              $this->view->categswithprodsalacarte =  $prodservice->getproducts($this->view->location->id, $this->view->selecteddate, 1);          // no xml; show "download pdf"         } else {             $this->setpdflink();             $this->renderscript('location/no_xml.phtml');         }     }      /**      * set pdflink view var depending on current location .      */     protected function setpdflink()     {         $this->view->pdflink = false;         if (strpos($this->view->location->url, 'city')) {             $this->view->pdflink = "http://meniu.lunchbox.ro/lunchbox.city.pdf";         } elseif (strpos($this->view->location->url, 'polus')) {             $this->view->pdflink = "http://meniu.lunchbox.ro/lunchbox.polus.pdf";         } elseif (strpos($this->view->location->url, 'sediu')) {             $this->view->pdflink = "http://meniu.lunchbox.ro/lunchbox.sediu.pdf";         } elseif (strpos($this->view->location->url, 'iulius')) {             $this->view->pdflink = "http://meniu.lunchbox.ro/lunchbox.iulius.pdf";         }             }     public function testareaction(){         // $this->getresponse()->setheader('content-type', 'application/json');         $this->_helper->layout->disablelayout();         $this->_helper->viewrenderer->setnorender(true);         $myarray =  $_post['data_post'];         $product_ids = $_post['product_ids'];         $type = 1;          echo "tralalalal";        // $model = new application_model_mapper_images();         $model = new application_model_ordernames();         echo  $model -> saveordernames();          echo "string";         //$this->view->string = $model -> saveordernames();      } } 

and images model class :

<?php  class application_model_mapper_images extends application_model_base_mapperabstract {     protected $dbname = 'location_images';      /**      * @param int $locationid      * @param array $imagenamesarr      *      array of basename files.      * @return false|array      *      return boolean false on insert error.      *      key: new image index, value: basename. i.e. array(1 => 'madonna.jpg')      */     public function batchinsertnewproductimages($locationid, array $imagenamesarr)     {         $newimgs = array();         $this->getzdb()->getadapter()->begintransaction();          try {             foreach ($imagenamesarr $baseimagename) {                 $newid = $this->getzdb()->insert(array('base_filename' => $baseimagename, 'location_id' => $locationid));                 $newimgs[$newid] = $baseimagename;             }             $this->getzdb()->getadapter()->commit();             return $newimgs;         } catch (zend_exception $e) {             $this->getzdb()->getadapter()->rollback();             return false;         }     }      /**      * @param int $productid      * @return array      *      container of application_model_object_image objects.      */     public function fetchallbylocationid($locationid)     {         $locationid = (int) $locationid;         $sql = $this->db->select()                         ->from('location_images')                         ->where('location_id = ?', $locationid)                         ->order('disp_order')                         ->order('base_filename'); // order alphabetically          $out = array();         foreach ($this->db->fetchall($sql) $imgrow) {              $out[] = $imgrow;         }         return $out;     }       public function reorderphotos(array $photos)     {         $disp_order = 0;         foreach ($photos $photo_id) {                 $sql = $this->db->select()->from('location_images')->where('id = ?', $photo_id);                 //verify if category exists in table                 if ($this->db->fetchrow($sql) != null) {                 ++$disp_order;                     if ($photos != "") {                     //change menu order                     $this->db->update('location_images',array('disp_order' => $disp_order), array('id = ?' => $photo_id));                     }                 }         }      }      public function test()     {         $sql = $this->db->insert("location_images", array('base_filename' => 'test.jpg', 'location_id'=>'1','disp_order'=>'22'));      }      /**      * @param int $id      * @return array      */     public function find($id)      {         return $this->getzdb()->find($id)->current();      }      /**      * @param string $imgbasename      * @return int      */     public function insertnew($imgbasename)     {         $imgbasename = trim($imgbasename);          // omit empty file names         if (empty($imgbasename)) { return 0; }          try {             return (int) $this->getzdb()->insert(array('base_filename' => (string) $imgbasename));         } catch (exception $e) {             return 0;         }     }     public function saveordernames(){              return 1;     } } 

as can see saveordernames function in both ordernames model , images model. can explain me why if use "images" model , string "string" testareaction function controller displayed , if use ordernames model, not ????


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -