简体   繁体   中英

codeigniter href with php variable doesn't work

i am trying to change the login button on my page to a logout button when someone is logged in.

$logged_in = $this->session->userdata('logged_in');
if ($logged_in) {

    $data['Lbutton'] = '<div id="login">
    <button class="login3"><?php echo anchor("pages/logout", "Logout"); ?></button>
  </div>';
} else {
    $data['Lbutton'] = '<div id="login">
    <button class="login3"><a href= <?php echo base_url()?>index.php/login>login</a>    </button>
  </div>';
}

and this is my view:

<?php echo $Lbutton ?>

This is Answer:

if ($logged_in) 
{
    $data['Lbutton'] = '<div id="login">
    <button class="login3">'.anchor("pages/logout", "Logout").'</button>
  </div>';
}
else
{
    $data['Lbutton'] = '<div id="login">
    <button class="login3"><a href="'.base_url().'index.php/login" >login</a>    </button>
  </div>';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM