Convenient $html->link()
I made this quick helper that extends Html Helper. While creating my very first plugin for cakephp 1.2, I decided to use Route so that I can save some space and time typing long controller names. Here is the sample code in my views:
echo $html->link( 'Link Test', array( 'controller' => 'long_controller_name', 'actions' => 'index', 'plugin' => 'long_plugin_name' ) );
I am a lazy typist and so I wanted to be able to use shortcut names for the array keys such as the following:
c = controller a = action p = plugin OR use numbers 0 = controller 1 = action 2 = plugin
I couldn’t find in the bakery any solution so I decided to create my own Html helper. Here is how you can install it:
First, add this file to your helpers folder located in /cakedir/app/views/helpers/. (Download XHTML Helper)
Then, in your controller file, include the Xhtml to your helpers list. Example
class MyController extends AppController {
...
var $helpers = array( 'Xhtml' );
...
}
That’s it. You can use it by doing the following:
echo $xhtml->link( 'Link Test', array( 'c' => 'long_controller_name', 'a' => 'index', 'p' => 'long_plugin_name' ) );
OR
echo $xhtml->link( 'Link Test', array( 'long_controller_name', 'index', 'long_plugin_name' ) );
Take note of using xhtml instead of html. I hope I don’t mislead anyone for using the name XHTML :P. I just want an extended HTML helper.
Tags: html helper, route
