So I have a contract that I want to edit for a customer. I happily click on the "EDIT" link and the form appears, but wait a minute, something's wrong! The "contract" tab in my menu isn't showing up as the active tab anymore.
The main contract page showed the active class with this in the navigation XML file:
<contract>
<label>Contracts</label>
<uri>/contract/</uri>
<resource>contract</resource>
<privilege>index</privilege>
</contract>
...and to view a contract, I simply use (as a page of the "contract" section):
<contract-view>
<label>View contract</label>
<uri>/contract/view/</uri>
<visible>0</visible>
</contract-view>
But if I want to view a contract, the ID goes through the url, as such: http://www.example.com/contract/view/123/
And when this happens, the navigation file doesn't detect that the current page is the one I want. To counter this, all you have to do is use the alternate method, which is a little longer but prevents any problem:
<contract-view>
<label>View contract</label>
<controller>contract</controller>
<action>view</action>
<visible>0</visible>
</contract-view>
When you specify the action and controller directly, the framework will take care of the rest, and even if you're using routes, everything will display smoothly. This is what I've set up for an URL like http://www.example.com/contract/123/view/
- in the navigation file:
<contract-view>
<label>View contract</label>
<controller>contract</controller>
<action>view</action>
<visible>0</visible>
</contract-view>
- in the routes.ini file:
routes.contractview.route = contract/:id/view
routes.contractview.defaults.controller = contract
routes.contractview.defaults.action = view
routes.contractview.defaults.id = 0
And there you have it! The Zend navigation and router will take care of the rest for you. Now it will detect the page you're on regardless of the URL, as long as the correct controller and action are defined in the configuration files. The beautiful tab is glowing as it should!
No comments:
Post a Comment