J.K.A.
J.K.A.

Reputation: 7404

Display controller name in small case in url + Zend framework

How to display controller name in small case in url in Zend Framework

Ex :

AlbumController.php

and I am using the following url:

<a href='/Album/'>album</a>

It is displaying Album name as "Album" as it is in url while I want to display it like "album" in to the url. Also I want to keep "Album" as it is in href tag.

How should I do this.

Please help me....thanks in advance.

Upvotes: 0

Views: 284

Answers (2)

iganev
iganev

Reputation: 128

You may get the controller name from the Request object when being inside the controller

$this->getRequest()->getControllerName();

Or access it globally

Zend_Controller_Front::getInstance()->getRequest()->getControllerName();

However, the best way to do this is using the "url" view helper in any view.

$this->url(array("module" => "default", "controller" => "album", "action" => "index"), "default");

The "module" parameter is optional. The second parameter "default" is the route to be used to build a reverse link, it is also optional. When using custom routes, make sure you define the "reverse" property of the route, ex.:

resources.router.routes.recipe_view.reverse = "recipes/%d-%s"

For more about routes configuration, see here For more view helpers, see here

Upvotes: 1

Tim Lytle
Tim Lytle

Reputation: 17624

Have you tried just making the URL lowercase? I'm fairly certain that using the default route for Zend Framework, the controller name is case insensitive. The action name is not however. If you camel case the action name, it changes the expected view script.

Update: Perhaps you just mean the url is title case while the link itself is not. If that's the case, just make the url lowercase:

<a href='/album/'>album</a>

Upvotes: 1

Related Questions