Solved

Zend Framework - removing /index/ from URLs

Posted on 2008-06-11
9
401 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:Squinky
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!  The _call solution worked.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 49

Accepted Solution

by:
Roonaan earned 75 total points
Comment Utility
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
Comment Utility
@PengiunMod

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

Author Comment

by:frankbeaton
Comment Utility
@ PenguinMod

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

772 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

9 Experts available now in Live!

Get 1:1 Help Now