• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] howto include anchor within normal $data-array

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

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

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

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.