开发者

problem with Zend URL helper $this->url

I have situation with Zend route & $this->url method

IN my bootstrap.php I have few routes as

 $route = new Zend_Controller_Router_Route(
        'dashboard',
        array(
            'action'     => 'index',
            'controller' => 'index',
            'module'     => 'dashboard',
            'isAdmin'    => true
        )
    );
    $router->addRoute('dashboard', $route);

$route = new Zend_Controller_Router_Route(
        'logout',
        array(
            'action'     => 'logout',
            'controller' => 'index',
            'module'     => 'main',
            'isAdmin'    => true
        )
    );
    $router->addRoute('logout', $route);

$route = new Zend_Controller_Router_Route(
        'manage-users',
        array(
            'action'     => 'list',
            'controller' => 'index',
            'module'     => 'main',
            'isAdmin'    => true
        )
    );
    $router->addRoute('manage-users', $route);

$route = new Zend_Controller_Router_Route(
        'edit-user/:id',
        array(
            'action'     => 'edit',
            'controller' => 'index',
            'module'     => 'main',
        ),
         array('id' => '[0-9]+')
    );
    $router->addRoute('edit-user', $route);


 $route = new Zend_Controller_Router_Route(
        '/manage-subcat/:ident',
        array(
            'action'     => 'index',
            'controller' => 'subcategory',
            'module'     => 'category',
            'ident'      => '',
            array(
                'ident' => '[a-zA-Z-_0-9]+',
            )
        )
    );
    $router->addRoute('manage-subcat', $route);

take a case of last route

in my view when I write

<a href="<?php echo $this->url(array ('controller'=> 'subcategory', 'action'=> 'index', 'module'=> 'category', 'ident' => $cats->catident ), 'manage-subcat', true ) ?>"><?php echo $cat->CategoryName ?></a>

I get url as http://127.0.0.10/manage-subcat

& when I disable the last route in bootstrap & then I write in my view file

<a href="<?php echo $this->url(array ('controller'=> 'subcategory', 'action'=> 'index', 'module'=> 'category', 'ident' => $cats->catident ) ) ?>"><?php echo $cat->CategoryName ?></a>

I get Url as same http://127.0.0.10/category/subcategory

Ideally I should get http://127.0.0.10/category/subcategory/ident/some-category for this one

& fo开发者_Go百科r previous one it should be http://127.0.0.10/manage-subcat/ident/some-category

This code sample is not working with custom routes as well as traditional routes, and I am trying to determine why this sample is not working correctly.


Besides the route declaration formatting error noted by zerocrates, could it be simply a typo in your code?

I notice you use $cat->CategoryName (singular $cat) in one place and $cats->catident (plural $cats) in another.

If passed a null parameter value, the router will omit that parameter from the generated URL.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜