Issues accessing a 2nd Skeleton module

For programming and general questions on Zend Framework

Issues accessing a 2nd Skeleton module

Postby cody4871 on Wed Jan 25, 2017 4:41 am

I created a bare-bones skeleton module, and I am finding that when trying to access it - it is routing to my default module.

NOTE: I added ~ to chop up the domain references to get around the linking policy

Module
- Admin (working/default module)
- Test (newly created skeleton module)

I have set-up a vhost - so that I can access my Admin module as such:

http://vanity.localhost/admin

Here is the .htaccess file (which is present in my 'public' folder)

Code: Select all
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]


From my httpd.conf file

Code: Select all
DocumentRoot "c:/Websites"
<Directory "c:/Websites">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
   FallbackResource disabled
</Directory>


From my httpd-vhosts.conf

Code: Select all
<VirtualHost *:80>
   ServerName vanity.localhost
   ServerAlias www.~vanity~.com
   DocumentRoot C:/Websites/Folder/Project/public
   SetEnv APPLICATION_ENV "development"
   ErrorLog "logs/vanity~.com-error.log"
       CustomLog "logs/vanity~.com-access.log" common

     <Directory C:/Websites/Folder/Project/public>
   DirectoryIndex index.php
         AllowOverride All
         Require all granted
     </Directory>

</VirtualHost>


Application.config.php

Code: Select all
return array(
    'modules' => array(
        'Admin','Test',
    ),
    'module_listener_options' => array(
        'module_paths' => array(
            './module',
            './vendor',
        ),
        'config_glob_paths' => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
    ),
);


The module.config for my main 'Admin' module is quite lengthy - so let me know if it there is anything that you would like to see.

Here is the module.config for the 'Test' module. I think the only thing i cahnaged was the route name?

Code: Select all
return array(
    'controllers' => array(
        'invokables' => array(
            'Test\Controller\Index' => 'Test\Controller\IndexController',
        ),
    ),
    'router' => array(
        'routes' => array(
            'test' => array(
                'type'    => 'Literal',
                'options' => array(
                    // Change this to something specific to your module
                    'route'    => '/index',
                    'defaults' => array(
                        // Change this value to reflect the namespace in which
                        // the controllers for your module are found
                        '__NAMESPACE__' => 'Test\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    // This route is a sane default when developing a module;
                    // as you solidify the routes for your module, however,
                    // you may want to remove it and replace it with more
                    // specific routes.
                    '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(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'Test' => __DIR__ . '/../view',
        ),
    ),
);


I have a feeling this has to do with the htaccess file but i'm kind of lost as to how to fix it. When I try to access: http://vanity.localhost/Test

I receive the following: "The requested URL could not be matched by routing."
cody4871
 
Posts: 5
Joined: Wed Feb 12, 2014 3:40 am

Re: Issues accessing a 2nd Skeleton module

Postby cody4871 on Thu Jan 26, 2017 4:12 am

Ok i figured it out - I was under the misconception that when you created a module, it automatically factored into the URL. So - a url might look something like this:

http://localhost/Module/Controller/Action

However - that is not the case - rather if you have two modules, the module.config gets merged together (the best way i can describe it). You must explicitly define the base route for the module, then define child routes that would pertain to controllers and actions. I don't know why that didn't dawn on me - but now it is crystal clear.
cody4871
 
Posts: 5
Joined: Wed Feb 12, 2014 3:40 am


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 7 guests