/ Published in: PHP
This is a custom HTML helper class based on CakePHP's built-in helper class, designed for constructing neater, well-formatted links.
There are plans to extend this further.
Expand |
Embed | Plain Text
<?php /** * * HTML helper class for the following: * * HTML anchor tags with mailto's * */ class HtmlHelper { // set the domain for environment var $domain = 'http://test.com/'; /** * Generate well-formatted links for scripts, CakePHP style * * */ // open the links and set the url, accounting for mailto links if (!empty($options) && is_array($options) && array_key_exists('type', $options) && $options['type'] == 'mailto') { $html_link = '<a href=mailto:"'.$url.'"'; } else { $html_link = '<a href="'.$this->domain.$url.'"'; } // set any other attributes from $options foreach ($options as $option => $value) { // filter for accepted options // only allow strings $html_link .= ' '.$option.'="'.$value.'"'; } } } } // close off the link $html_link .= '>'.$name.'</a>'; return $html_link; } } // for testing purposes only // $Html = new HtmlHelper; // echo $Html->link('test', 'adamcbrewer@gmail.com', array('class'=>'some-class', id'=>'the id', 'title'=>'This is the tile', 'rel'=>'the_rel', 'onClick'=>'alert()'));
You need to login to post a comment.
