-1
할 수있는 두 가지 방법이 있습니다
라우팅ZendFramework 2 - 왜이 라우팅 내가 배열 방법을 사용 방지하고 어디 작동하지
1) module.config.php 배열을 사용하는 한 가지 방법은 (그렇게하려고하지 않습니다) 2) 다른 방법 설명서가 있습니다 (예 : http://evan.pro./zf2-router-talk.html#slide11)
나는 수동 방법을 얻지 만 실패하고 있습니다. 어디서 Module.php 다음과 같은 생각이 간단한 수동 라우팅 작업을 만드는 방법?
[Thu Oct 25 11:07:50 2012] PHP Fatal error: Class 'Application\Literal' not found in ...
<?php
namespace Application;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
// router
use Zend\Mvc\Router\Http;
use Zend\Mvc\Router\SimpleRouteStack;
class Module {
public function onBootstrap(MvcEvent $e) {
$router = new Http\TreeRouteStack();
// Http\Literal::factory(array(
$route = Literal::factory(array(
'route' => '/index',
'defaults' => array(
'controller' => 'index',
'action' => 'index',
),
));
$router->addRoute('foo', $route);
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
// This is for preDispatch
$eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_DISPATCH, array($this, 'preDispatch'), 100);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
echo "0";
}
public function preDispatch() {
echo "1";
}
public function getConfig() {
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig() {
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
후속 :가 어떻게 젠드 프레임 워크 2 사용자 매뉴얼 작업을 할 수 있습니다 모듈/응용 프로그램/설정에있는 module.config.php 파일을 무시/...
public function onBootstrap(MvcEvent $e) {
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
// This is for preDispatch
$eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_DISPATCH, array($this, 'preDispatch'), 100);
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// this is the router part
$router = $e->getApplication()->getServiceManager()->get('router');
// this works too
//$route = new Http\Literal(
// '/foo',
// array('controller' => 'foo')
// );
// OR
// this works too
$route = Http\Literal::factory(array(
'route' => '/foo',
'defaults' => array(
'controller' => 'Application\Controller\IndexController',
'action' => 'foo'
),
));
$router->addRoute('foo', $route, null);
}
그래도 라우팅은 작동하지 않습니다. 오류가 표시되지 않지만. – YumYumYum
$ router = $ e-> getApplication() -> getServiceManager() -> get ('router'); 그런 다음 해당 라우터에 새 $ route를 추가하십시오. 그것은 당신이 새로운 라우터를 만들어서 루트를 붙인 다음 그 라우터 객체로 아무 일도하지 않는 것처럼 보입니다. 이 방법이 효과가 있다면 답변을 업데이트하겠습니다. – DrBeza
감사합니다. 나는 위에 업데이트했다. – YumYumYum