Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZF][ZF2][ZendFramework2] Zend Nie znajduje klasy kontrolera
Forum PHP.pl > Forum > PHP > Frameworki
CzlowiekSkrypt
Przerabiam kurs ze Strefy Kursów Zend Framework no i postanowil się na mnie ten framework obrazić. Jak już nawet StackOverflow nie pomaga to wiedz że twój kod jest przeklęty.

gdy chcę wyświetlić stronę główną projektu to dostaję takiego babola :

File:
C:\xampp\htdocs\php\zendcms\skeleton-application\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php:168

Message:
Zend\Mvc\Controller\ControllerManager::createFromInvokable: failed retrieving "productcontrollerproduct(alias: Product\Controller\Product)" via invokable class "Product\Controller\ProductController"; class does not exist

Było kilka rozwiązań tego na necie jednak żadne mi nie pomogło. Męczę się z tym już parę godzin i nie wiem gdzie jest ten chochlik co blokuje wczytanie klasy.

Uwaga - zapodaję kodem :

Struktura modułu
Product
=> config -> module.config.php
=> src -> Product -> Controller -> ProductController.php
---->Form
---->Model
=>view
---->product->product
---->autoload_classmap.php
=>Module.php

Plik module.config.php
  1. <?php
  2. return array(
  3. 'controllers' => array(
  4. 'invokables' => array(
  5. 'Product\Controller\Product' => 'Product\Controller\ProductController',
  6. ),
  7. ),
  8. 'router' => array(
  9. 'routes' => array(
  10. 'product' => array(
  11. 'type' => 'segment',
  12. 'options' => array(
  13. 'route' => '/product[/][:action][/][/:id]',
  14. 'constraints' => array(
  15. 'action' => '|a-zA-Z||a-zA-Z0-9_-|*',
  16. 'id' => '[0-9]+'
  17. ),
  18. 'defaults' => array(
  19. 'controller' => 'Product\Controller\Product',
  20. 'action' => 'index',
  21. ),
  22. ),
  23. ),
  24. ),
  25. ),
  26.  
  27. 'view_manager' => array(
  28. 'template_path_stack' => array(
  29. 'product' => __DIR__ . '/../view',
  30. ),
  31. ),
  32. );


Plik ProductController.php
  1. <?php
  2. namespace Product\Controller;
  3. use Zend\Mvc\Controller\AbstractActionController;
  4. use Zend\View\Model\ViewModel;
  5.  
  6. class ProductController extends AbstractActionController{
  7.  
  8. public function indexAction(){
  9.  
  10. }
  11.  
  12. public function addAction(){
  13.  
  14. }
  15.  
  16. public function editAction(){
  17.  
  18. }
  19.  
  20. public function deleteAction(){
  21.  
  22. }
  23. }


Plik Module.php

  1. <?php
  2. namespace Product;
  3.  
  4. class Module{
  5.  
  6. public function getAutoloaderConfig(){
  7. return array(
  8. 'Zend\Loader\ClassMapAutoloader' => array(
  9. __DIR__ . '/autoload_classmap.php',
  10. ),
  11. 'Zend\Loader\StandardAutoloader' => array(
  12. 'namespaces' => array(
  13. __NAMESPACE__ => __DIR__ . '/src/'. __NAMESPACE__,
  14. ),
  15. ),
  16. );
  17. }
  18.  
  19. public function getConfig(){
  20.  
  21. return include __DIR__ . '/config/module.config.php';
  22. }
  23. }


autoload_classmap zwraca tylko pustą tablicę.
Namespace 'Product' jest zarejestrowany w application.config.php

Wiem że widoki nie są zdefiniowane ale wtedy powinien wywalić właśnie taki błąd a nie że nie ma klasy która de facto jest smile.gif
crafter
a spróbuj z takim routerem
  1. 'router' => array(
  2. 'routes' => array(
  3. 'product' => array(
  4. 'type' => 'Literal',
  5. 'options' => array(
  6. // Change this to something specific to your module
  7. 'route' => '/product',
  8. 'defaults' => array(
  9. // Change this value to reflect the namespace in which
  10. // the controllers for your module are found
  11. '__NAMESPACE__' => 'Product\Controller',
  12. 'controller' => 'Product',
  13. 'action' => 'index',
  14. ),
  15. ),
  16. 'may_terminate' => true,
  17. 'child_routes' => array(
  18. // This route is a sane default when developing a module;
  19. // as you solidify the routes for your module, however,
  20. // you may want to remove it and replace it with more
  21. // specific routes.
  22. 'default' => array(
  23. 'type' => 'Segment',
  24. 'options' => array(
  25. 'route' => '/[:controller[/:action]]',
  26. 'constraints' => array(
  27. 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
  28. 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
  29. ),
  30. 'defaults' => array(
  31. ),
  32. ),
  33. ),
  34. ),
  35. ),
  36. ),
  37. )

a moduł masz dodany do application.config.php ?
wasyllinio
zdaje mi się, że modyfikacja routera -> 'defaults' starczy
  1. <?php
  2. return array(
  3. 'controllers' => array(
  4. 'invokables' => array(
  5. 'Product\Controller\Product' => 'Product\Controller\ProductController',
  6. ),
  7. ),
  8. 'router' => array(
  9. 'routes' => array(
  10. 'product' => array(
  11. 'type' => 'segment',
  12. 'options' => array(
  13. 'route' => '/product[/][:action][/][/:id]',
  14. 'constraints' => array(
  15. 'action' => '|a-zA-Z||a-zA-Z0-9_-|*',
  16. 'id' => '[0-9]+'
  17. ),
  18. 'defaults' => array(
  19. '__NAMESPACE__' => 'Product\Controller',
  20. 'controller' => 'product',
  21. 'action' => 'index',
  22. ),
  23. ),
  24. ),
  25. ),
  26. ),
  27.  
  28. 'view_manager' => array(
  29. 'template_path_stack' => array(
  30. 'product' => __DIR__ . '/../view',
  31. ),
  32. ),
  33. );
  34. );
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.