控制器的方法,这些方法仅被AJAX技术,让私人? [英] Controller methods that are only called by AJAX, make private?

查看:76
本文介绍了控制器的方法,这些方法仅被AJAX技术,让私人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的控制器,如 forgot_password 方法登录等。

I have methods on my controllers like forgot_password, login etc.

这些只能通过AJAX调用,但在默认情况下,你可以通过URL浏览到他们由于CI的工作方式。

These are only called via AJAX but by default you can browse to them via URL due to the way CI works.

我能以某种方式让他们私人,仍然通过AJAX访问它们?什么是这里做过的事?

Can I somehow make them private and still access them via AJAX? What's the done thing here?

推荐答案

这里最好的做法是使用 $这个 - >输入 - > is_ajax_request()

The best practice here is to use $this->input->is_ajax_request()

if(! $this->input->is_ajax_request()) {
    redirect('404');
}

这篇关于控制器的方法,这些方法仅被AJAX技术,让私人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆