Hi everyone,
I'm a newbie to ZF2 and I have a question to the routing.
I downloaded a Hello World - Demo package. After setting up the virtual host, I can access under
http://zf2.local. But when I tried zf2.local/hello-world, the server showed me always the 404 Not Found Error.
I spent hours trying to find out where the error is but I couldn't see anything wrong.
This is my Module.php
public function getConfig()
{
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'HelloWorld\Controller\Index',
'action' => 'index',
),
),
),
'hello-world' => array(
'type' => 'Literal',
'options' => array(
'route' => '/hello-world',
'defaults' => array(
'__NAMESPACE__' => 'HelloWorld\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(
),
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'HelloWorld\Controller\Index' => 'HelloWorld\Controller\IndexController'
),
),
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/view',
),
),
);
}
And this is how I configured in MAMP/conf/apache/httpd.conf
NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Users/Lina/zf2-demo/public"
ServerName zf2.local
#SetEnv APPLICATION_ENV "development"
# <Directory "/Users/Lina/HelloWorld/public">
# DirectoryIndex index.php
# AllowOverride All
# Order allow,deny
# Allow from all
# </Directory>
</VirtualHost>
Notes: I have to toggle comment or MAMP server doesn't work.
I appreciate every feedback.
Lina