beginner2016 beginner2016 - 4 months ago 23
PHP Question

Codeigniter links trouble

I am using codeigniter framework for my college project, and I having some problems with links, when i do something like this in my view:

<li> <a href="<?php echo site_url('Controller_test/testFunction') ?>">CLICK ME</a> </li>


It all works great, but when I try to put link inside my array for example CLICK ME link, like this:

$links = array(
'links' =>"<li class='dropdown'>"
. "<a href='#' class='dropdown-toggle' data-toggle='dropdown' >TEST links <span class='caret'></span></a>"
. "<ul class='dropdown-menu'>"
. "<li> <a href="<?php echo site_url('Controller_test/testFunction') ?>">CLICK ME</a> </li>"
. "<li> <a href='#'>TEST 1</a> </li>"
. "<li> <a href='#'>TEST 2</a> </li>"
. "</ul>"
. "</li>"
);


the problem occurs. I cannot understand where I make mistake. Thanks to everyone willing to help me!

Answer

You are written php tag inside php tag . Need to rewrite your code as

 $links = array(
                'links' =>"<li class='dropdown'>"
                . "<a href='#' class='dropdown-toggle' data-toggle='dropdown' >TEST links <span class='caret'></span></a>"
                . "<ul class='dropdown-menu'>"
                . "<li> <a href='".site_url('Controller_test/testFunction')."'>CLICK ME</a> </li>"
                . "<li> <a href='#'>TEST 1</a> </li>"
                . "<li> <a href='#'>TEST 2</a> </li>"
                . "</ul>"
                . "</li>"   
            );