Zend Framework 2 - Routing doesn't work

139 views
Skip to first unread message

Lina

unread,
May 3, 2013, 9:25:49 AM5/3/13
to zfdeve...@googlegroups.com
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


elzo valugi

unread,
May 3, 2013, 9:35:27 AM5/3/13
to zfdeve...@googlegroups.com
Try to look into your MAMP apache error logs to see what fails. Do you have the htaccess in place?

Lina


--
You received this message because you are subscribed to the Google Groups "Zend Framework Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zfdevelopers...@googlegroups.com.
To post to this group, send email to zfdeve...@googlegroups.com.
Visit this group at http://groups.google.com/group/zfdevelopers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages