Page 1 of 1

Zend Framework Config

Posted: Wed Jan 13, 2010 12:20 pm
by volomike
Have a quick Zend Framework question.

Let's say I'm tired of going into views and then scripts for my views. Let's say I want to just put the subdirs under views/scripts right into the views folder itself, thereby eliminating the scripts folder. What would I have to change in the ZF config to make that possible?

Re: Zend Framework Config

Posted: Wed Jan 13, 2010 3:54 pm
by Eran
setScriptPath()
http://framework.zend.com/manual/en/zen ... ript-paths

If you're using the viewRenderer (I usually don't) you'd need to change the view objects it uses
http://framework.zend.com/manual/en/zen ... lpers.html

Re: Zend Framework Config

Posted: Wed Jan 13, 2010 9:46 pm
by volomike
The setScriptPath won't work. It keeps asking for a "scripts" subfolder. If you implement Quickstart example for ZF and then run the example given by ZF for the setScriptPath, you'll see this same error.

The fix is the following in the application/Bootstrap.php file:

Code: Select all

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
  protected function _initView() {
    $oView = new Zend_View();
    $oView->addScriptPath(APPLICATION_PATH . '/views');
    $oRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
    $oRenderer->setView($oView);
    return $oView;
  }
}
 

Re: Zend Framework Config

Posted: Wed Jan 13, 2010 9:57 pm
by volomike
Next Question

How do I eliminate the need for the "Controller" suffix in the filename of a Zend Framework controller? It just gets tiresome to keep typing that suffix in when creating controllers, and meanwhile the file is already in a controllers folder so it's superfluous.

For instance, by default the homepage on a site goes to "controllers/IndexController.php". What if I want it to go to "controllers/Index.php"?

Re: Zend Framework Config

Posted: Thu Jan 14, 2010 6:09 am
by josh
"Dispatching is the process of taking the request object, Zend_Controller_Request_Abstract, extracting the module name, controller name, action name, and optional parameters contained in it, and then instantiating a controller and calling an action of that controller"
http://framework.zend.com/manual/en/zen ... tcher.html

12.6.2. Subclassing the Dispatcher

Also they setup the default path with the scripts/ subdir on purpose for a reason. If you use Zend_View_Helper they would go in views/helpers by convention. There are other conventions ZF follows. Although I personally am with you. I put my helpers in a folder called View so they work with auto-loading.

SO I would have paths like this, personally:

Module/
Module/views/scripts
Module/View/Helper/Foo.php
Module/View.php

I put the scripts mostly out of convention. Like later on I might add more "layers" like translation files, but yeah I'm with you on how annoying the extra folders can be, at times.

One thing Magento did that exacerbates that problem is they stored the views away from the Model code

they have

app/code/core/Mage/Module/Model.php

and then it's view would be in

app/design/frontend/default/default/module/whatever.phtml

and it would store CSS and such in

/skin/frontend/default/default/etc...

Pretty ridiculous. Example of what NOT to do.