0
I created a new module in zend, but it gives error 404.
modules.config.php
return [
'Zend\Router',
'Zend\Validator',
'Application',
'Album' <-- módulo que foi criado.
];
module.config.php
namespace Album;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'controllers' => [
'factories' => [
Controller\AlbumController::class => InvokableFactory::class,
],
],
// The following section is new and should be added to your file:
'router' => [
'routes' => [
'album' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\AlbumController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
'album' => __DIR__ . '/../view',
],
],
];
Module.php
namespace Album;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements ConfigProviderInterface
{
const VERSION = '3.0.3-dev';
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
}
Albumcontroller
namespace Album\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class AlbumController extends AbstractActionController
{
public function indexAction()
{
return ViewModel();
}
}
Folder structure:
-Album
-config
-module.config.php
-src
-Controller
-AlbumController.php
-Module.php
-view
-album
-album
-index.phtml
-error
-layout
I already did! But it’s not working anyway.
– Jonathan de Toni
Did you run the dump-autoload Composer on the terminal as well? By the way, you need to run it inside the project folder, where is Composer.json Another detail, is your cache enabled? If yes, try clearing the data/cache directory
– Rodrigo Teixeira Andreotti
Rodei, appeared "Generating autoload files". I also tried to clear the cache. It doesn’t work yet.
– Jonathan de Toni
Okay, I’ll try to simulate here in my environment... I’m copying all the classes you posted to find out
– Rodrigo Teixeira Andreotti
Well... come on, here in my simulations it worked, two notes here, first in the modules.config.php file, include before the controllers this: Album, ie full namespace ( Album Controller Albumcontroller::class), second remark, in your controller you are returning Viewmodelcomo if it was a function, and zend requires this return to be an instance of the Viewmodel class, ie missing the new reserved word before, would look like this: Return new Viewmodel(); - I will complement my answer with these items ;-)
– Rodrigo Teixeira Andreotti
Dude, file continues with the problem. I deleted the module and redo it all again, and it still didn’t work. What else could it be. It gives as if it were a route error, by not finding the page.
– Jonathan de Toni
Is there a way to get this project into git or gist for us to see? Why here I copied exactly the same folder structure as you, saved with the same names, copied your source code... rs There must be something in the middle of the way cluttering the middle of the field
– Rodrigo Teixeira Andreotti
https://github.com/jonathandetoni/teste
– Jonathan de Toni
Well... I edited the answer with some more notes I made in your source... rs
– Rodrigo Teixeira Andreotti
I went up with the tests I was trying, however, I made the corrections and committed again, and it still wasn’t. I will give up this framework and migrate to Windows
– Jonathan de Toni
This is the error it gives me: The requested URL could not be Matched by routing.
– Jonathan de Toni
Let’s go continue this discussion in chat.
– Rodrigo Teixeira Andreotti