CodeIgniter(PHP)中的编码跟随/取消关注系统& Twitter的引导。我也有为URLS活动的路由。按照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
答案 0 :(得分: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';
}
?>