CodeIgniter Forums
[solved] howto include anchor within normal $data-array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [solved] howto include anchor within normal $data-array (/showthread.php?tid=4026)



[solved] howto include anchor within normal $data-array - El Forum - 11-03-2007

[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? ;-)


[solved] howto include anchor within normal $data-array - El Forum - 11-03-2007

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



[solved] howto include anchor within normal $data-array - El Forum - 11-03-2007

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


[solved] howto include anchor within normal $data-array - El Forum - 11-03-2007

[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.


[solved] howto include anchor within normal $data-array - El Forum - 11-03-2007

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