[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Zend Framework - removing /index/ from URLs

Posted on 2008-06-11
9
Medium Priority
?
410 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

650 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