Solved

Zend Framework - removing /index/ from URLs

Posted on 2008-06-11
9
403 Views
Last Modified: 2009-10-21
Sorry if this is a simple question, but I'm just getting my feet wet with Zend Framework (7 years exp. with PHP itself, but ZF is new to me) and I'd like to avoid having to create separate controllers for every page on the site, if I can help it.  I'd prefer to have each page (account, reports, etc.) expressed as an action in the indexController, and then handle all the business logic in individual models.  30+ controllers that contain nothing but an indexAction() method sort of seems like a waste of time and code.

In short, I want URLs formatted as "[hostname]/account/" rather than "[hostname]/index/account/", etc., without having to actually create a separate controller for account.

Is this possible?  Any ZF gurus out there?  Is there a way to, say, tell the framework to use the first URL param as an action of the IndexController if no corresponding controller name is found?

Am I making sense, or should I have gotten some sleep before posting this?  ;)

Thanks,

-Frank
0
Comment
Question by:frankbeaton
9 Comments
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 21763847
Can't tell you off the top of my head, but I'd highly recommend you take a look at some of the Zend tutorials on the ZF router class, and also try asking on the ZF fw-general mailing list - the Zend guys on there are extremely helpful.
0
 
LVL 1

Assisted Solution

by:kkretsch
kkretsch earned 50 total points
ID: 21801979
I think you can just create the indexController with a __call function inside which gets all actions dispatched. So you have your short urls with just one path element per action.
0
 

Author Comment

by:frankbeaton
ID: 21805464
Thanks!  The _call solution worked.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 49

Accepted Solution

by:
Roonaan earned 75 total points
ID: 21816524
Have you tried using a custom Zend_Router_Route_Regex which set the default controller to index?

        $routes['dynamic1'] = new Zend_Controller_Router_Route_Regex(
              "(.*)"
              ,
              array(
                    'controller' => 'index' //default controller
                    ,
                    'action' => 'index'
              )
              ,
              array('action' => 1)
        );

        $controller = Zend_Controller_Front::getInstance();
        $controller->getRouter()->addRoutes($routes);
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21819982
@PengiunMod

Providing alternative solutions to answered question has never been a bad thing, has it?
0
 

Author Comment

by:frankbeaton
ID: 21824167
@ PenguinMod

Sorry.  I'm new to EE.  Didn't realize I accepted my own comment as the solution.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now