Jump to content

Recommended Posts

I want to route everything to the index controller that is /action-name. How do I do this and still  have /controller/action-name dispatch correctly?

Also, I don't want to specify an action since I am using _call and render() in the controller .  I am doing this because I have a lot of simple views and I don't want empty controller function. Thanks in advance.

 

[

php]$route = new Zend_Controller_Router_Route_Regex(

    '(\w+)',

    array(

        'controller' => 'index',

        'action'    => ''

    ));[/code]

 

Link to comment
https://forums.phpfreaks.com/topic/219393-zf-routes/
Share on other sites

Why do you need to have everything in the IndexController? If you create a controller for each of those you already have the desired result and closer to a correct implementation:

 

class FooController extends Zend_Controller_Action {
    function indexAction() {}
}

class BarController extends Zend_Controller_Action {
    function indexAction() {}
}

 

domain.top/foo

domain.top/bar

Link to comment
https://forums.phpfreaks.com/topic/219393-zf-routes/#findComment-1137620
Share on other sites

I have dozens of view scripts that are basic html so I don't want to create empty controller functions and I definitely don't want to set up dozens of additional controllers with an empty index function. This route seems to do the trick. However the second one is necessary to make the home page / work. Is there a way to combine the two?

$router->addRoute('pages', 
    		new Zend_Controller_Router_Route(
        	'/:action',
        		array('controller' => 'index', 'action' => ':action')
    		)
	);

	$router->addRoute('index', 
    		new Zend_Controller_Router_Route(
        	'/',
        		array('controller' => 'index', 'action' => 'index')
    		)
	);

 

Link to comment
https://forums.phpfreaks.com/topic/219393-zf-routes/#findComment-1137624
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.