Codeigniter请求控制类
我正在尝试为自己做一个好的简单的请求控制库。
这是我的代码:
class CI_Request
{
public function isAjax()
{
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
}
public function isPost()
{
return isset($_POST);
}
public function isGet()
{
return isset($_GET);
}
}
但我不知道我是否正确。
有什么建议吗? :P
真的谢谢
i'm trying to do myself a good simple request control library.
this is my code:
class CI_Request
{
public function isAjax()
{
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
}
public function isPost()
{
return isset($_POST);
}
public function isGet()
{
return isset($_GET);
}
}
but i don't know if i'm right.
any suggestions? :P
really thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先你的问题很模糊。
您需要首先了解助手和库是框架内的两个独立实体
库通常是一个类,它是处理特定任务的方法的集合,这就是为什么我认为库就是您所寻找的。
的内容如下所示。
您可以在应用程序目录的
application/libraries
中创建一个库文件,并创建一个名为MyRequest.php
的文件,该文件 名称和类名是相对的,因此它们必须相同,从控制器加载库很简单注意:很长时间没有接触 CI,所以代码可能不准确。
Firstly your question is very vague.
You need to first understand tha Helpers and Libraries are two separate entities within the framework
And libraries is usually a class thats a collection of methods to handle a specific task, witch is why i think libraries are what your looking for.
You can create a library file within
application/libraries
of your application directory and create a file calledMyRequest.php
, the contents of that file would be like so..The file name and the class name are relative so they must be the same, loading the library from a controller is simple
Note: haven't touched CI for long time so code may not be exact.