如何回复<a> tag which has an href that is using php echo base_url()

时间:2015-04-27 13:15:26

标签: php html codeigniter

Hi I am trying to produce a <td> which also contains an <a> link which will redirect to a function in my controller which also echos the id of my data. Here is my code so far:

<?php 
    if ($this->session->userdata("username")==$info->U_username) {
        echo '<td><a href="<?php echo base_url()gamestalker/edit_content/<?php echo $info->C_id;?>">EDIT</a></td>';
    }
?>

This code produces an error Disallowed Key characters. Any help or comment is highly appreciated.

4 个答案:

答案 0 :(得分:2)

对于串联字符串,PHP具有.运算符。

echo '<td><a href="' . base_url() . 'gamestalker/edit_content/' . $info->C_id . '">EDIT</a></td>';

答案 1 :(得分:0)

您需要将base_url()的结果添加到要输出的字符串中,例如:

echo '<td><a href="' . base_url() . '/gamestalker/edit_content/' . $info->C_id . '">EDIT</a></td>';

答案 2 :(得分:0)

要么你需要连接而是多次使用php。像这样使用

validation: { max: new Date('12/1/2006') }

或者不要将html包含在像这样的php标签中

<?php 
    if ($this->session->userdata("username")==$info->U_username){
        echo "<td><a href='".base_url()."'/gamestalker/edit_content/'".$info->C_id."'>EDIT</a></td>";
    }
?>

答案 3 :(得分:0)

您需要字符串连接。在PHP中,您可以使用.

同样,codeigniter的base_url可以提出一个论点:

<?php 
    if ($this->session->userdata("username")==$info->U_username){
        echo '<td><a href="'.base_url('gamestalker/edit_content/'.$info->C_id).'">EDIT</a></td>';
    }
?>