0

在 CodeIgniter(PHP) 和 Twitter-Bootstrap 中编码关注/取消关注系统。我也有为 URL 激活的路由。按照 VIEW 中的按钮代码。

 <!-- Follow Button Start -->
<?php $is_logged_in = $this->session->userdata('is_logged_in'); ?>
<?php if(!(empty($is_logged_in)) && $sID != $vID && !in_array($sID, $following)): ?>
    <button class="btn" type="submit" onClick="location.href='<?php echo site_url("follow/$vUsername"); ?>'">Follow <?php echo $vUsername; ?> </button>
<?php elseif (in_array($sID, $following)):?>
    <button class="btn" type="submit" onClick="location.href='<?php echo site_url("unfollow/$vUsername"); ?>'">UnFollow <?php echo $vUsername; ?> </button>
<?php else: ?>
    <button class="btn disabled" type="submit">Follow <?php echo $vUsername; ?> </button>
<?php endif; ?>
<!-- Follow Button End -->

即使用户没有关注,按钮也会显示UnFollow $vUsername

4

1 回答 1

0

我不能在这里完全测试它,但这对我来说更有意义:

<?php if((!empty($is_logged_in)) && ($sID != $vID) && (!in_array($sID, $following))): ?>

编辑:

好吧,在这种情况下,只有简单的逐步调试可以节省您的时间:

<?php 
$is_logged_in = $this->session->userdata('is_logged_in'); 

if(!empty($is_logged_in))
{
    echo '$is_logged_in is not empty';
}

echo '$sID is: '.$sID.' and it should not be equal to $vID'. $vID;

if($sID != $vID){
    echo 'and indeed it is not';
}
else
{
    echo 'but it is. Here is the problem';
}

echo 'This is the $following array:';
print_r($following);

if(!in_array($sID, $following))
{
    echo '$sID is not in the $following array';
}
else
{
    echo '$sID IS in the $following array';
}   

?>
于 2012-07-11T12:26:12.890 回答