Archive for the ‘Helpers’ Category
jQuery star rating problem with brackets []
If you used the star rating plugin of jQuery in cakePHP, you might experienced that the hover effects are not working properly. This is because one of the class name used to identify the buttons uses the radio button name. This will be a problem in cakephp because we use brackets in names.
In order to fix that, we need to remove them. Here is quick fix. Open file jquery.rating.js:
from (line 97):
// grouping:
var n = this.name;
to:
// grouping:
var real_name = this.name;
var n = real_name.replace(/[^A-Za-z0-9_\-]/g, '-'); // remove unwanted characters
from (line 108):
$.rating.groups[n].valueElem = $('
');
to:
$.rating.groups[n].valueElem = $('
');
I have reported this in the bugtracker and I hope it will be included in the next release.
Tags: bug fixes, jQuery, star rating
Making Clickable Images on CakePHP
Hello again,
Yesterday, i stumbled upon this problem on how am i suppose to create an image with a link on it. I needed to know it because of my goal. I wanted to use images as my buttons to navigate the admin pages. So without further ado, here’s how:
1. We will use HTML Helpers Image and Link, and we shall combine this 2.
2. For Image,
Syntax:
$html->image(string $path, array $htmlAttributes, boolean $return = false);
Example:
$html->image(’/img/images/cancel.png’, array(’class’ => ’save_button’));
3. For Link,
Syntax:
$html->link(string $title, string $url, array $htmlAttributes, string $confirmMessage = false, boolean $escapeTitle = true, boolean $return = false);
Example:
$html->link(’SAVE’, ‘/registers’, array(), false, false, false);
4. So to make an image clickable,
<?php echo $html->link($html->image(’/img/images/cancel.png’,array(’class’ => ’save_button’)), ‘/registers’, array(), false, false, false); ?>
That’s it. I hope this will help you in the future.
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
