Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Routed anchor links
  • Small code i used to create routed acnhor-links. <code>
    # Route
    'page/:key' => array('index/view', 'name' => 'name_of_route',) # Code
    <?php echo Html::routed_anchor(Router::get('name_of_route'), 'Anchor text', array('key' => 'val')); ?> # Output
    <a href="http://mysite.com/page/val">Anchor text</a>
    </code> <code>
    /**
    * Creates an html link based on a route
    *
    * @param string the url
    * @param string the text value
    * @param array the data array
    * @param array the attributes array
    * @param bool true to force https, false to force http
    * @return string the html link
    */
    public static function routed_anchor($href, $text = null, $data = array(), $attr = array(), $secure = null)
    {
    $anchor = Html::anchor($href, $text, $attr, $secure); foreach($data as $key => $val)
    {
    $anchor = preg_replace('#:'.$key.'#', $val, $anchor);
    } return $anchor;
    }
    </code>
  • What is wrong with
    <?php echo \Router::get('name_of_route', array('key' => 'val')); ?>
    

    which should do exactly that?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion