我真的是CodeIgniter的新手。
我正在尝试设置一个网站,其中用户必须登录才能查看页面。我来自Java,我采用的是分层的方法。
我的想法是编写我自己的Controller基础:
<?php
class MY_Controller extends Controller
{
function Controller()
{
parent::Controller();
if(!$this->quickauth->logged_in())
{
//they need to login, send them to the login page.
}
}
}
?>现在,我可以编写控制器来扩展它,并且我将确保它们将始终被登录。
以下是登录页面的概要:
<?php
class login extends Controller
{
function index()
{
//Lets just double check, they might not have to login.
if ($this->quickauth->logged_in())
{
//send them to the main controller
}
}
}
?>如你所见,我已经走到这一步了。我需要替换什么:
用什么?
有没有更好的方法来做这件事?
谢谢,布莱克
发布于 2010-12-02 15:54:39
重定向很容易。
只需使用:
redirect('controller/method');是,加载url helper以访问重定向功能。
$this->load->helper('url);由于url helper经常被使用,你应该在config/autoload中自动加载它。
发布于 2010-12-02 13:35:51
如果你加载'url_helper‘,你有一个重定向函数在里面。有关url helper的更多信息,请阅读文档。
发布于 2010-12-03 12:51:21
您也可以像这样使用soemthing
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if (!isset($is_logged_in) || $is_logged_in != true)
{
echo 'You don't have permission to access this page. <a href="http://lemonrose.net">Login</a>';
die();
//$this->load->view('login_form');
}
}您可以在此基础上进行构建
https://stackoverflow.com/questions/4331746
复制相似问题