3

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

& for 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.

3
  • The "validation" array for that last route is inside the "defaults" array. Commented Apr 8, 2011 at 17:57
  • @zerocrates u mean to say I should change it to this >> $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); OK that was a silly mistake & I did that too yet URL is not having :ident property in it Commented Apr 8, 2011 at 19:27
  • You should use the static router for the parameterless routes Commented Apr 10, 2011 at 23:25

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

hey man ur right u know copy paste mistake ...... I also started using Static routes. things are good again thanks
@ankur You may want to check this as the right answer (check mark button)
@Chris Thanks for the show of support but I don't think ankur is coming back any time soon ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.