zend framework2 - How to call on view on dyanmic actions in zf2 -


hello friends new in zf2. stuck @ 1 place. in project want to call 1 view on many action. url "baseurl/g/any-thing-from-from-database" want call view on "any-thing-from-from-database" action module or same.

my g module have code on module.config.php

 return array(  'controllers' => array(      'invokables' => array(          'g\controller\g' => 'g\controller\gcontroller',      ),  ),    'router' => array(      'routes' => array(          'g' => array(              'type'    => 'segment',              'options' => array(                  'route'    => '/g[/:action][/:id]',                  'constraints' => array(                      'action' => '[a-za-z][a-za-z0-9_-]*',                      'id'     => '[0-9]+',                  ),                  'defaults' => array(                      'controller' => 'g\controller\g',                      'action'     => 'g',                  ),              ),          ),      ),  ),   'view_manager' => array(       'template_path_stack' => array(          'g' => __dir__ . '/../view',      ),  ),  ); 

on gcontroller.php

         namespace g\controller;       use zend\mvc\controller\abstractactioncontroller;      use zend\view\model\viewmodel;      use zend\stdlib\requestinterface request;      use zend\stdlib\responseinterface response;      use zend\view\renderer\phprenderer;      use students\form\studentsform;      use students\model\students;        class gcontroller extends abstractactioncontroller             {                 public function dispatch(request $request, response $response = null)                         {                             $controller = $this->params('controller');                              $nicname = $this->params('action');                              if($nicname !== false){                                   $hosts = $this->getservicelocator()->get('manager\model\hoststable');                                   if(($data = $hosts->findbynicname($nicname)) !== null){                                       $captchaservice = $this->getservicelocator()->get('sancaptcha');                                      $form = new studentsform($captchaservice);                                       return array('from'=>$form);                                  }                               }                                  return $this->redirect()->toroute('home',array('controller'=>'application','action'=>'index'));                          }                       public function gaction()                     {                         return new viewmodel();                     }              } 

to different actions url have used dispatch function working correctly. when action database want show form content different module named students or g. code showing header , footer , nothing else without error.please me out.thanks in advance.

i think overwriting dispatch method cannot good.

i'm sure don't see anything, because don't ever render viewmodel, no data there. because disabled default dispatch behaviour , overwrite action argument in route. if open http://my.website/g/foobar foobaraction() called - if dispatch work correctly.

so simple rename action param (for example) foo, take logic gaction() , ever have $this->param('foo').


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -