0

The router is okay, it works via address bar The router is okay if I echo the URL The app stops working if I echo $this->url('routename')

Guys, this is the router:

'ownedGoods' => array( 'type' => 'Zend\Mvc\Router\Http\Literal', 'options' => array( 'route' => '/owned', 'defaults' => array( 'controller' => 'index\index', 'action' => 'indexOwned' ) ) ), 

this is the invokable for controllers

'index\index' => 'AddGoods\Controller\IndexController', 

Now when i open the URL: http://goodsApp.localhost:88/owned, it works

The trouble arised when I put along other links in navigation bar, where as other links like Add Goods and Home is working, but the owned is not.

 <li class="active"><a href="<?php echo $this->url('home') ?>"><?php echo $this->translate('Home') ?></a></li> <li class="active"><a href="<?php echo $this->url('add') ?>"><?php echo $this->translate('Add a good') ?></a></li> <li class="active"><a href="<?php echo $this->url('owned') ?>"><?php echo $this->translate('My Goods') ?></a></li> 

App is not running, no controller and route is matched. Even not for home page, it shows

Uncaught exception 'Zend\Mvc\Router\Exception\RuntimeException' with message 'Route with name "owned" not found' in path\to\app\vendor\zendframework\zendframework\library\Zend\Mvc\Router\Http\TreeRouteStack.php:313 Stack trace: #0 path\to\app\vendor\zendframework\zendframework\library\Zend\View\Helper\Url.php(100): Zend\Mvc\Router\Http\TreeRouteStack->assemble(Array, Array) #1 [internal function]: Zend\View\Helper\Url->__invoke('owned') #2 #2 path\to\app\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php(400): call_user_func_array(Object(Zend\View\Helper\Url), Array) #3 path\to\app\module\Application\view\layout\layout.phtml(48): Zend\View\Renderer\PhpRenderer->__call('url', Array) #4 path\to\app\module\Application\view\layout\layout.phtml(48): Zend\View\Renderer\PhpRenderer->url('owned') in path\to\app\vendor\zendframework\zendframework\library\Zend\Mvc\Router\Http\TreeRouteStack.php on line 313

But, if I remove the nav bar link (the last li tag) from navigation, it again works. Even if instead of this->url('owned') I just echo 'owned' it still works.

The problem is only when I echo this->url('owned') in nav bar, it stops working and give the exception. It works if i use the route by address bar or by any other mean, like echoing 'owned' in nav bar.

Any more questions, ask me freely.

1 Answer 1

1

Because your route name is ownedGoods Not owned

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

2 Comments

it works now. But why it was working before when I typed goodsApp.localhost:88/owned. And when I echo 'owned' in a tag? while it just not worked when I type echo this->url('owned'). The difference. Please.
owned is the last segment in your URL route. ownedGoods is the unique key of the route

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.