好的,所以我现在有一个测试页面,它只是在测试我的积分系统。几乎当用户按下按钮时,它会给他们 5 分。现在的问题是每次我刷新页面时,用户都会得到 5 分。这怎么了?如有必要,我可以发布库和模型功能。这是控制器和视图:
欢迎.php 视图:
Hi, <strong><?php echo $username; ?></strong>! <?php echo $fullname ?> is now logged in now. </br>
You have <?php echo $points; ?> Points.</br>
<?php echo anchor('/auth/logout/', 'Logout'); ?></br>
<?php echo form_open('add_points'); ?>
<?php echo form_submit('/auth/add_points/', 'Get 5 free Points!'); ?>
<?php echo form_close(); ?>
<?php echo var_dump($pointhistory); ?>
Welcome.php 控制器:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library('tank_auth');
$this->lang->load('tank_auth');
}
function index()
{
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$data['fullname'] = $this->tank_auth->get_fullname();
$data['points'] = $this->tank_auth->get_points();
$data['pointhistory'] = $this->tank_auth->get_point_history();
$this->load->view('welcome', $data);
}
}
}