在 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