?
Solved

Zend Framework - removing /index/ from URLs

Posted on 2008-06-11
9
Medium Priority
?
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 150 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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 49

Accepted Solution

by:
Roonaan earned 225 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

770 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