开发者

Zend Framework - module routing

开发者 https://www.devze.com 2023-03-28 23:43 出处:网络
I have a module called users. Inside I have an index controller, with an action called part1Action() inside the index controller class.

I have a module called users. Inside I have an index controller, with an action called part1Action() inside the index controller class.

I expected to be able to access the part1Action() action through the path /user/index/part1, but I'm ending up in the /user/index/index action.

I have other modules set up that ar开发者_Python百科e working from a module/controller point of view, but I've not tried accessing other actions apart from the index action in these, so this is the first time I've tried routing to other than the index action.

More info, I have this in my application.ini:

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
autoloaderNamespaces[] = "Users_"

Where am I going wrong?


part1Action is not going to be a valid Action name as it contains a number. Name the action something like partOneAction. If you absolutely want to use a number in your url set up a routing rule like so

$front->getRouter()->addRoute(
    'part-1',
    new Zend_Controller_Router_Route_Static(
        '/user/index/part1/',
        array('module' => 'users', 'controller' => 'index', 'action' => 'part-one')
    )
);

Honestly though, I would probably set my module up a little differently. I'm assuming that this is for a multi-page form of some kind?

so:

modules
    user
        controllers
            {some-meaningful-name}Controller.php

inside of {some-meaningful-controller-name}Controller.php

    public function {some-meaningful-action-name}Action()
    {
        $part = $this->getRequest()->getParam('part', 1);
    }

that way your url would be

/user/{some-meaningful-controller-name}/{some-meaningful-action-name}/part/{some-number}

0

精彩评论

暂无评论...
验证码 换一张
取 消