【发布时间】:2011-12-15 12:22:54
【问题描述】:
我正在使用 Codeigniter 构建我的项目。
在这里我有一些疑问或需要澄清一下。
我可以使用构造函数来做一些影响 codeigniter/php 中所有其他功能的事情吗??
请看这里:
<?php
class New extends CI_Controller
{
function __construct()
{
//Constructor codes...
}
function Create_page() //The user need to be Logged in to perform this
{
//Checking whether the user logged in or not if yes allowed else denied.
}
function Edit_page() //The user need to be Logged in to perform this
{
//Checking whether the user logged in or not if yes allowed else denied.
}
function Delete_page() //The user need to be Logged in to perform this
{
//Checking whether the user logged in or not if yes allowed else denied.
}
function about_us() //This is a public action no need to Log in
{
// this is a pulic action ,no need to check the login status
}
}
?>
如您所见,我需要检查每个私人功能的登录状态,
有什么方法可以在构造函数上做到这一点?这样构造函数就会检查是否登录......但它只需要影响一些功能......
【问题讨论】:
-
所有公共函数都有
-
哦...什么是合乎逻辑的?公共=私人? (这就是你的意思是合乎逻辑的?)
-
你不应该避免使用保留关键字(“New”)作为类名吗?
-
@landons 这只是一个例子,请不要介意类名。
标签: php function codeigniter login constructor