Tuesday 15 April 2014

php - Zend framework 1.12 front controller configuration -


I try to register my module with the front controller using the bootstrap class using the code given below I am:

  $ this-> Bootstrap ('FrontController'); $ Front = $ this- & gt; GetResource ('FrontController'); $ Front & gt; AddModuleDirectory (APPLICATION_PATH "/ module".); $ Front-> SetParam ('prefix default module' is true);   

This works fine and all modules are registered. But when I do the following, my module directory is not registered and I get "no controller found error".

  $ front = Zend_Controller_Front :: getInstance (); $ Front & gt; AddModuleDirectory (APPLICATION_PATH "/ module".); $ Front-> SetParam ('prefix default module' is true);   

As the front controller applies a singleton design pattern, both code blocks should not mention the same example and should both my code block work?

The issue is that this application is in your application.ini:

 < Code> Resources.frontController.controllerDirectory = APPLICATION_PATH "/ controller"   

This directory is not included in the file structure you provided, so I think you can remove it Will solve the problem.

Why it works in one way and the other is not:

There are two ways to configure resources with the Zend app: class processing and Plugin Resource Application.ini has resources.xxx line plugin resources, and _init methods are classroom resources to run class resources before plug-in resources But, if you have $ this-> If you run Bootstrap ('...') then it will ensure that the resource is started (regardless of type).

Then in your first code example, $ this-> Bootstrap ('front-controller'); launches the front controller resource which you have defined in your application.ini. This then sets the controller directory from which you gave it. You then add a module directory, which is actually used in your application.

In your second code example, you get an example of the front controller and then add your module directory to it (all good). But then plug-in resources will run (after remembering these runs). This will get your existing Front Controller instance, but the module directory is set to the Override controller directory, so this causes your error later.

I am usually trying and avoid mixing and matching plug-ins and class resources can cause some strange problems. So either apply it to everything. Put it in or all of the bootstrap class. Personally, I am much more readable later.

If you need the controller directory, by adding the $ this-> bootstrap ('FrontController'); Second code example should also work, as this will trigger the plugin resource.

No comments:

Post a Comment