你好朋友我是zf2中的新朋友。我堅持在一個地方。在我的項目中,我想對許多操作調用一個視圖。 我的網址是「baseurl/g/any-thing-from-from-database」 我想從另一個模塊或同一個模塊調用「來自數據庫的任何事情」操作的視圖。如何打電話查看zf2中的dyanmic動作
我的G卡有GController.php
namespace G\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Stdlib\RequestInterface as Request;
use Zend\Stdlib\ResponseInterface as 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();
}
}
上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',
),
),
);
這個代碼從我用的是正常工作調度功能的URL不同的動作。當我從數據庫中得到這個動作時,我想用來自不同模塊的一些名爲學生或G的內容顯示錶單。但是,此代碼只顯示頁眉和頁腳,沒有任何其他錯誤。請幫助我。提前感謝。
感謝您的回覆,但如何啓用默認調度行爲 – user3666505 2015-04-02 07:36:53
我的意思是不覆蓋調度方法。 – danopz 2015-04-03 14:05:07
你明白了嗎? – danopz 2015-08-20 12:13:54