Solved

Zend Framework - removing /index/ from URLs

Posted on 2008-06-11
9
402 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hacked File Timestamps 4 50
converting numbers with php 3 31
How to keep line breaks when outputting data from database 4 15
php function to remove a file 26 7
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

896 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

15 Experts available now in Live!

Get 1:1 Help Now