Re: [fw-general] Zend Framework + Doctrine Module Autoloader issue
Thanks to all for the input. I want to continue down the road of a resource plugin for my Doctrine configuration since it is what I think the resource plugin is meant to provide. I envision for my application that I will configure the DB Adapter in the application configuration and within my Bootstrap I will load the adapter dynamically based on that configuration. So let me pose this question differently and I hope some Zend people will comment. Is it currently possible from within a Resource Plugin to modify, update the default module autoloader object configuration when it is instantiated the application configuration? If so, how? If not, does this seem like a valid enhancement? --David -- View this message in context: http://www.nabble.com/Zend-Framework-%2B-Doctrine-Module-Autoloader-issue-tp24392765p24431101.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend Framework + Doctrine Module Autoloader issue
I am using ZF 1.8.4 and Doctrine 1.1.2 with a module directory setup of +---application | +---configs | \---modules | +---default | | +---controllers | | \---views | | \---scripts | | +---error | | \---index | +---error | | +---controllers | | \---views | | \---scripts | | \---error | \---user | +---controllers | +---models | | \---generated | \---views | \---scripts | \---index +---library | \---App | \---Application | \---Resource +---public | +---images | \---themes | \---default | \---css \---tests +---application \---library I have a resource file called Doctrine.php in my library folder which does the following: $zla = Zend_Loader_Autoloader::getInstance(); $zla-unshiftAutoloader( array( 'Doctrine', 'autoload' ), 'Doctrine' )-setFallbackAutoloader( true ); $manager = Doctrine_Manager::connection( $this-_getConnectionString() ); $manager = Doctrine_Manager::getInstance(); $manager-setAttribute( Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE ); $manager-setAttribute( Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_NONE ); $manager-setAttribute( Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true ); $manager-setAttribute( Doctrine::ATTR_USE_DQL_CALLBACKS, true ); $manager-setAttribute( Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true ); My config xml file has this: --- snip --- pluginPaths App_Application_Resource![CDATA[App/Application/Resource]]/App_Application_Resource /pluginPaths resources frontController defaultmodule![CDATA[default]]/defaultmodule params prefixDefaultModule![CDATA[true]]/prefixDefaultModule usedefaultcontrolleralways![CDATA[false]]/usedefaultcontrolleralways /params /frontController modules default![CDATA[default]]/default error![CDATA[error]]/error user![CDATA[user]]/user /modules !-- Doctrine application plugin -- doctrine dbtype![CDATA[dbtype]]/dbtype dbhost![CDATA[localhost]]/dbhost dbname![CDATA[dbname]]/dbname dbuser![CDATA[dbuser]]/dbuser dbpass![CDATA[dbpass]]/dbpass /doctrine !-- View application plugin -- view![CDATA[view]]/view /resources --- snip --- The default Module Autoloader is loaded correctly during bootstrapping, making available the default resource types (form, model, dbtable), but I use Doctrine so dbtable is not used and I would like to insert, override or even replace the default resource type(s) with a folder in models that Doctrine uses which is 'generated'. My preference is that when my Resource Plugin which configures Doctrine as my DB layer, also can inject the needed resource type into the default module autoloader, in order to make the configuration available in all modules. I have tried for the past day to get this to work but all of the examples I find are to create a module autoloader in the module bootstrap file which means (as I understand it) that I have to do this for each module bootstrap. I am still new to Zend and struggling a bit with the changes in v1.8, so I may have just missed the example that shows how this is done. Of course my ultimate problem here is that when I try to load a model User.php in the models folder which extends generated\BaseUser.php, the BaseUser class is not found. Thanks, David -- View this message in context: http://www.nabble.com/Zend-Framework-%2B-Doctrine-Module-Autoloader-issue-tp24392765p24392765.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Looking for code feedback
First let me start by saying I am fairly new to ZF and with this post I am primarily looking for feedback for improvement from the Zend experts on my solution and hopefully, if list solution is reasonable, others may have some information, where I found it difficult to find. My Goal: With my ZF Application setup for modules (module/controller/action), I wanted to: 1. remove index from the URL (I find it a nuisance) 2. if I requested /module/action, that the App would catch the error of action not being a controller and check to see if it was an action in the index controller of that module. So I could use /event/list instead of /event/index/list. Here is my solution: class App_Controller_Plugin_CustomRoutes extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request ) { $dispatcher = Zend_Controller_Front::getInstance()-getDispatcher(); $moduleName = $request-getModuleName();//e.g. user $controllerName = $request-getControllerName();//e.g. index $actionName = $request-getActionName();//e.g. list // example: creates Module_IndexController class name // out of $moduleName and $controllerName $className = $dispatcher-formatControllerName($moduleName . '_' . $controllerName); //e.g. Module_IndexController $controllerFileName = $dispatcher-formatControllerName($controllerName) . '.php';//e.g. IndexController.php // check if a class name was created if ($controllerFileName) { $validControllerFile = Zend_Loader::isReadable($controllerFileName); if ($validControllerFile) { // this is a valid controller - exit now return; } else { // Couldn't load the class (controller). // lets see if this is an action in the index controller $actionName = $controllerName; $controllerName = $dispatcher-getDefaultControllerName(); // example: takes Index and creates IndexController class name to see if it exists $className = $dispatcher-formatControllerName($moduleName . '_' . $controllerName); $controllerFileName = $dispatcher-formatControllerName($controllerName) . '.php'; if($className $controllerFileName) { try { $methodName = $dispatcher-formatActionName($actionName); Zend_Loader::loadFile($controllerFileName,null,true); $class = new ReflectionClass( $className ); if( $class-hasMethod( $methodName ) ) { // we only arrive here if can't find controller or action $request-setControllerName($controllerName); $request-setActionName($actionName); // this will force plugins to fire again $request-setDispatched( false ); } else { // action does not exist either, return so 404 will be thrown return; } } catch (Zend_Exception $e) { // Couldn't load the class with method. No need to act, // just catch the exception and fall out of the // if } } } } } } Thank You, David -- View this message in context: http://www.nabble.com/Looking-for-code-feedback-tp23377593p23377593.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend Framework Routing
using ZF 1.7.3 and module/controller/action configuration The current default routing behavior in Zend Framework is as stated in the documentation: 10.5.4. Default routes Zend_Controller_Router_Rewrite comes preconfigured with a default route, which will match URIs in the shape of controller/action. Additionally, a module name may be specified as the first path element, allowing URIs of the form module/controller/action. Finally, it will also match any additional parameters appended to the URI by default - controller/action/var1/value1/var2/value2. So if I navigate to a module name that does not exist, the router will automatically look for a controller of the same name, if it finds a controller with that name it will serve it. I have two requests: 1. Zend extends that functionality to controllers and actions. If I navigate to a controller name that does not exist, the default router will automatically look for an action of that same name in the index controller. This would effectively remove the need to put 'index' (controler) in the URI. 2. Being somewhat new to ZF, I would like some guidence on how to extend or customize the current default router to accomplish this. David -- View this message in context: http://www.nabble.com/Zend-Framework-Routing-tp21834663p21834663.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend Framework Routing
Chris, These are not assumptions. This is my understanding after spending the last two days reading the Zend documentation (and every post I could find on the subject). Maybe I am still new enough to Zend not to be able to grasp the routing concepts or maybe they just don't make sense to me. In either case I have exhausted the Zend documentation on this subject and need some help from others. I have tried what I believe to be Route Chaining unsuccessfully. My understanding of route chaining is that if one route does not match, go to the next route. Here is some sample code bits from my bootstrap.php that show what I have tried unsuccessfully with chains (keep in mind the current order of these routes is insignificant since I have tried them in every order possible): self::$router = self::$frontController-getRouter(); $route = new Zend_Controller_Router_Route( '/:module', array('module' = ':module', 'controller' = 'index', 'action' = 'index') ); self::$router-addRoute('module', $route); $route = new Zend_Controller_Router_Route( '/:module/:controller', array('action' = 'index')); self::$router-addRoute('controller', $route); $route = new Zend_Controller_Router_Route( '/:module/:action', array('module'='default', 'controller'='index', 'action'='index')); self::$router-addRoute('action', $route); Now my understanding from the documentation is that these routes are added to a chain in order. If the first route that is checked does not match it goes to the next route. Here is how I thought the above code should work. If I type in host.com/modulename, it finds the module. If I type in host.com/modulename /controllername I get Action controllername does not exist and was not trapped in __call() but if I type in host.com/modulename/index/actionname it works. Now if I put the action route above the controller route (under the module route), the following works: host.com/modulename, host.com/modulename/controllername, host.com/modulename /controllername/actionname or host.com/modulename/index/actionname. This surprises me because I thought the order of this route chain was module - action - controller, which to me means that if I type in host.com/modulename/controllername I should get an error that the controllername is not a valid action. What I am trying to achieve here is to be able to type host.com/modulename/actionname and for the route controller to first check for a controller called actionname and if it does not exist, look in the indexcontroller for action actionname. So if you can shed some light on how route chains are defined and used and possibly share an example of how I could achieve the above, that would be great. Aside from that if I need to overwrite the standard router, I can do that but as I mentioned before I am not sure how to do this. David Chris Weldon wrote: David, I think you need to disavow the assumptions in terms of how things are routed and write your own routes for things you need. This will help reduce confusion on how to specify requests from the URL. Documentation on how to do this can be found on the same page: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes You can make it cleaner by defining routes in an XML config file. But, the short of it is continue reading and you'll get a better idea of how to implement routes in ZF. -- Chris Weldon On Wed, Feb 4, 2009 at 10:56 AM, dbroderick davidbroder...@boisestate.edu wrote: using ZF 1.7.3 and module/controller/action configuration The current default routing behavior in Zend Framework is as stated in the documentation: 10.5.4. Default routes Zend_Controller_Router_Rewrite comes preconfigured with a default route, which will match URIs in the shape of controller/action. Additionally, a module name may be specified as the first path element, allowing URIs of the form module/controller/action. Finally, it will also match any additional parameters appended to the URI by default - controller/action/var1/value1/var2/value2. So if I navigate to a module name that does not exist, the router will automatically look for a controller of the same name, if it finds a controller with that name it will serve it. I have two requests: 1. Zend extends that functionality to controllers and actions. If I navigate to a controller name that does not exist, the default router will automatically look for an action of that same name in the index controller. This would effectively remove the need to put 'index' (controler) in the URI. 2. Being somewhat new to ZF, I would like some