2014-12-22 3 views
-1

마지막으로 zf2 설치에 성공했습니다. 이제는 함수에 액세스하려고 시도하지만 404 페이지를 얻습니다.젠드 2의 컨트롤러에서 함수에 어떻게 액세스합니까?

이것은 내 코드입니다. 네임 스페이스 Application \ Controller; 나는 그것이 나 리디렉션/내 링크가 404 이유에를 추가 액세스

use Zend\Mvc\Controller\AbstractActionController; 
use Zend\View\Model\ViewModel; 

class IndexController extends AbstractActionController{ 

    public function indexAction(){ 
     return new ViewModel(); 
    } 
    public function addAction(){ 
     echo 1; 
    } 

    public function editAction(){ 
    } 

    public function deleteAction(){ 
    } 
} 

?

는 경로입니다 : 내가 함수 addAction에 액세스 할 수있는 경로를 수정해야 할 경우

return array(
    'router' => array(
     'routes' => array(
      'home' => array(
       'type' => 'Zend\Mvc\Router\Http\Literal', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         'controller' => 'Application\Controller\Index', 
         'action'  => 'index', 
        ), 
       ), 
      ), 
      // The following is a route to simplify getting started creating 
      // new controllers and actions without needing to create a new 
      // module. Simply drop new controllers in, and you can access them 
      // using the path /application/:controller/:action 
      'application' => array(
       'type' => 'Literal', 
       'options' => array(
        'route' => '/application', 
        'defaults' => array(
         '__NAMESPACE__' => 'Application\Controller', 
         'controller' => 'Index', 
         'action'  => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'default' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => '/[:controller[/:action]]', 
          'constraints' => array(
           'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
          ), 
          'defaults' => array(
          ), 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
    'service_manager' => array(
     'abstract_factories' => array(
      'Zend\Cache\Service\StorageCacheAbstractServiceFactory', 
      'Zend\Log\LoggerAbstractServiceFactory', 
     ), 
     'aliases' => array(
      'translator' => 'MvcTranslator', 
     ), 
    ), 
    'translator' => array(
     'locale' => 'en_US', 
     'translation_file_patterns' => array(
      array(
       'type'  => 'gettext', 
       'base_dir' => __DIR__ . '/../language', 
       'pattern' => '%s.mo', 
      ), 
     ), 
    ), 
    'controllers' => array(
     'invokables' => array(
      'Application\Controller\Index' => 'Application\Controller\IndexController' 
     ), 
    ), 
    'view_manager' => array(
     'display_not_found_reason' => true, 
     'display_exceptions'  => true, 
     'doctype'     => 'HTML5', 
     'not_found_template'  => 'error/404', 
     'exception_template'  => 'error/index', 
     'template_map' => array(
      'layout/layout'   => __DIR__ . '/../view/layout/layout.phtml', 
      'application/index/index' => __DIR__ . '/../view/application/index/index.phtml', 
      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
      'error/index'    => __DIR__ . '/../view/error/index.phtml', 
     ), 
     'template_path_stack' => array(
      __DIR__ . '/../view', 
     ), 
    ), 
    // Placeholder for console routes 
    'console' => array(
     'router' => array(
      'routes' => array(
      ), 
     ), 
    ), 
); 

누군가가 나를 설명 할 수 ??? 또는 새 컨트롤러에 액세스 하시겠습니까? 예 : myproject/mynewcontroller 또는 myproject/add? 내가 젠드에서 라우팅을 사용하지 않은 이후로는,이 코드가 유효한 경우 완전히 확실하지 않다

'router' => array(
     'routes' => array(
     'index' => array(
      'type' => 'Literal', 
      'options' => array(
       'route' => '/add', 
       'defaults' => array(
        '__NAMESPACE__' => 'Application\Controller', 
        'controller' => 'Index', 
        'action' => 'add', 
       ), 
      ), 

: 들으

+0

내가 돈, t는 모든 기능과 컨트롤러에 대한 이해 새로운 경로를 만들어야합니까? –

+0

예, 모든 기능과 컨트롤러에 대해 새로운 경로를 만들어야합니다. 이것이 zend MVC의 작동 방식입니다. – NoCode

+0

방금 ​​내 게시물을 업데이트했습니다. 다시 확인해주세요. –

답변

0

당신의 라인을 따라 그 기능이 무엇인가를 호출 경로를 구성해야 하지만 그 방향으로 뭔가 있어야합니다. 더 이노의 젠드 프레임 워크 문서를 참조하십시오 : http://framework.zend.com/manual/current/en/modules/zend.mvc.routing.html

+0

나는 여전히 404와 같은 나의 URL에 액세스하고 있습니다. myproject.com/index/add –

+0

이것이 내 project.com/add의 결과라고 생각합니다. 하지만 웹 서버의 다시 쓰기 규칙을 올바르게 설정해야합니다. 그렇지 않으면 myproject.com/index.php/add가 작동 할 수 있습니다. – NoCode

0

당신이 당신의 module.config.php 파일에 컨트롤러 invokables을 추가하는 것을 잊지 수도있을 이 시도 :

<?php 

return array(
    'controllers' => array(
     'invokables' => array(
      'Application\Controller\Index' => 'Application\Controller\IndexController', 
     ), 
    ), 
    ... 
    ... 
); 
관련 문제