Zend Framework Config

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Zend Framework Config

Post 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?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Zend Framework Config

Post 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
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Re: Zend Framework Config

Post 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;
  }
}
 
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Re: Zend Framework Config

Post 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"?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Zend Framework Config

Post 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.
Post Reply