2016-09-06 2 views
0

뭔가를하기 위해 자신의 모델을 만들려고합니다. (계산이있을 것이고, 데이터베이스와 기타 지정되지 않은 작업이있을 것입니다). 하지만 클래스를 찾을 수 없다는 오류가 계속 발생하기 때문에 문제가 발생합니다. 여기 PHP Zend 2 : 치명적인 오류 - 클래스를 찾을 수 없음

는 컨트롤러 (모듈/신청/SRC/애플리케이션/컨트롤러/IndexController.php)

namespace Application\Controller; 

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

class IndexController extends AbstractActionController 
{  

    public function indexAction() 
    { 
     $this->layout('layout/layout'); 
    } 

    public function cennikAction() { 
     $this->layout('layout/pusty'); 
     $logika_paczki = new Przesylki(); 
     echo $logika_paczki->return_word(); 
    } 
} 

Module.php (모듈/신청/SRC/Module.php)

namespace Application; 

use Main\Model\Przesylki; 

class Module 
{ 
    const VERSION = '3.0.2dev'; 

    public function getAutoloaderConfig() 
    { 
     return array(
      'Zend\Loader\ClassMapAutoloader' => array(
       __DIR__ . '/autoload_classmap.php', 
      ), 
      'Zend\Loader\StandardAutoloader' => array(
       'namespaces' => array(
        __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, 
       ), 
      ), 
     ); 
    } 

    public function getConfig() 
    { 
     return include __DIR__ . '/../config/module.config.php'; 
    } 
} 

및 모델, Przesylki.php (모듈/응용 프로그램/SRC/응용 프로그램/모델/Przesylki.php) :

namespace Main\Model; 

class Przesylki 
{ 
    public function return_word() { 
     return "word"; 
    } 
} 

필요한 경우,

namespace Application; 

use Zend\Router\Http\Literal; 
use Zend\Router\Http\Segment; 
use Zend\ServiceManager\Factory\InvokableFactory; 

return [ 
    'router' => [ 
     'routes' => [ 
      // Home 
      'home' => [ 
       'type' => Literal::class, 
       'options' => [ 
        'route' => '/', 
        'defaults' => [ 
         'controller' => Controller\IndexController::class, 
         'action'  => 'counter', 
        ], 
       ], 
      ], 
      'work' => [ 
       'type' => Literal::class, 
       'options' => [ 
        'route' => '/work', 
        'defaults' => [ 
         'controller' => Controller\IndexController::class, 
         'action'  => 'index', 
        ], 
       ], 
      ], 
      'cennik' => [ 
       'type' => Literal::class, 
       'options' => [ 
        'route' => '/cennik', 
        'defaults' => [ 
         'controller' => Controller\IndexController::class, 
         'action'  => 'cennik', 
        ], 
       ], 
      ], 
      // Panel 
      'panel' => [ 
       'type' => Segment::class, 
       'options' => [ 
        'route' => '/panel', 
        'defaults' => [ 
         'controller' => Controller\PanelController::class, 
         'action'  => 'index', 
        ], 
       ], 
      ], 
      'test' => [ 
       'type' => Segment::class, 
       'options' => [ 
        'route' => '/panel/test', 
        'defaults' => [ 
         'controller' => Controller\PanelController::class, 
         'action'  => 'test', 
        ], 
       ], 
      ], 
     ], 
    ], 
    'controllers' => [ 
     'factories' => [ 
      Controller\IndexController::class => InvokableFactory::class, 
      Controller\PanelController::class => InvokableFactory::class, 
     ], 
    ], 
    'view_manager' => [ 
     'display_not_found_reason' => true, 
     'display_exceptions'  => true, 
     'doctype'     => 'HTML5', 
     'not_found_template'  => 'error/404', 
     'exception_template'  => 'error/index', 
     'template_map' => [ 
      'layout/layout'   => __DIR__ . '/../view/layout/layout.phtml', 
      'layout/panel'   => __DIR__ . '/../view/layout/panel_layout.phtml', 
      'layout/counter'   => __DIR__ . '/../view/layout/counter.phtml', 
      'layout/pusty'   => __DIR__ . '/../view/layout/pusty.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' => [ 
      __DIR__ . '/../view', 
     ], 
    ], 
]; 

디렉토리 : : autoload_classmap.php (모듈/응용 프로그램/SRC/autoload_classmap.php 그냥

return array(); 

module.config.php입니다

/config 
    /autoload 
/data 
    /cache 
/module 
    /Application 
     /config 
      module.config.php 
     /src 
      /Application 
       /Controller 
        IndexController.php 
        PanelController.php 
       /Model 
        Przesylki.php 
      autoload_classmap.php 
      Module.php 
     /test 
     /view 
/public 

을 내가 실행할 때/Cennik 나는 치명적이다, 그 종류는 발견되지 않는다 :

[Tue Sep 06 08:58:20.446371 2016] [:error] [pid 4934] [client 195.8.99.234:1129] PHP Fatal error: Class 'Main\\Model\\Przesylki' not found in /var/www/Paczucha_pl/module/Application/src/Main/IndexController.php on line 27 

실제 파일 및 네임 스페이스 :

Przesylki.php - Application\Model 
IndexController - Application\Controller 
PanelController - Application\Controller 
module.config.php - Application 
Module.php - Application 

답변

1

마지막으로 해결책을 찾았습니다. 주어진 네임 스페이스에 대한 올바른 구조는 다음과 같습니다.

/module 
    /Application 
     /config 
      module.config.php 
     /src 
      /Controller 
       IndexController.php // => Namespace : Application\Controller 
       PanelController.php // => Namespace : Application\Controller 
      /Model 
       Przesylki.php   // => Namespace : Application\Model 
     /view 
     /index 
      /index 
     /panel 
      /panel 

두 개 이상의 응용 프로그램 폴더가 없어야합니다. Zend 3이라고 생각합니다. 아마도 바뀌었을 것입니다.

2

네임 스페이스에 문제가 있습니다. 모듈 네임 스페이스가 Application이므로 모델 네임 스페이스가 Application\Main\Model이어야합니다.

모듈 구조가 ZF2에 권장되지 않습니다. 다음과 같은 형식이어야합니다.

/module 
    /Application 
     /config 
      module.config.ph 
     /src 
      /Application 
       /Controller 
        IndexController.php // => Namespace : Application\Controller 
        PanelController.php // => Namespace : Application\Controller 
       /Model 
        Przesylki.php   // => Namespace : Application\Model 
     /view 
      /index 
       /index 
      /panel 
       /panel 
+0

정보 주셔서 감사합니다. 추천대로 디렉토리를 만들려고했지만 지금은 모든 색인이 발견되지 않습니다. 저기서 코드를 변경했는데 왜 라우팅이 작동하지 않는지 확인할 수 있습니까? 오류 코드 : [Tue Sep 06 11 : 23 : 59.214235 2016] [: 오류] [pid 4937] [클라이언트 195.8.99.234:59632] PHP 치명적 오류 : 'Application \\ Controller \\ IndexController'클래스를 찾을 수 없습니다./var/www/Paczucha_pl/vendor/zendframework/zend-servicemanager/src/Factory/$ –

+0

@KarolGasienica 모듈 구조를 업데이트 한 후 모든 네임 스페이스를 업데이트합니까? 모듈 구조에 따라 전체 응용 프로그램의 네임 스페이스를 확인해야합니다. –

+0

무엇이 잘못되었는지 확인할 수 있습니까? 나는 그것을 올바르게 설정했다고 생각합니다 ... https://github.com/Xantias/paczucha_public –

관련 문제