CodeIgniter Forums

Full Version: [solved] howto include anchor within normal $data-array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]UnrealMinds[/eluser]
I have a view where I want to include dynamic - over the controller defined - links.


the following works fine:

controller:
$data['links'] = '<a href="./impress">Impress</a> | <a href="./test">test</a> ';

view:
&lt;?=$links?&gt;


but I would like to use the "anchor"-function.

the following doesn't work:

controller:
$data['links'] = "&lt;?=anchor('impress', 'Impress')?&gt; | &lt;?=anchor('test', 'test')?&gt;";



How can I do that? ;-)

El Forum

[eluser]mironcho[/eluser]
Try this:
Code:
$this->load->helper('url');
$data['links'] = anchor('impress', 'Impress') . ' | ' . anchor('test', 'test');

El Forum

[eluser]UnrealMinds[/eluser]
cool - thanx! ;-)

El Forum

[eluser]Majd Taby[/eluser]
UnrealMinds - the reason that doesn't work is because &lt;?=anchor('foo','bar'); ?&gt; is equivalent to &lt;?php echo anchor('foo','bar'); ?&gt;. So two things, first of all, when you're in php code (within &lt;?php and ?&gtWink, you don't use those tags, anything inside them is interpreted as php code. Also, anchor() returns the html, so you don't want to echo it out in the controller, instead you want to assign it, that's why you don't see echo in mironcho's code.

El Forum

[eluser]UnrealMinds[/eluser]
thanx for this description - I understand now