一般在AJAX提交后,通过这个函数返回Controller执行的数据结构。在Controller中使用。 如果是jsonp,则URL中需要带上callback参数
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $status | Int | 是 | 0:错误信息|1:正确信息 |
| $message | String | 否 | 显示的信息 |
| $data | Array | 否 | 订单数据 |
| $type | String | 否 | 返回数据类型,json|xml|eval|jsonp |
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$this->controller->ajax_return(1, '操作成功'); //直接返回JSON数据
}
public function test() {
echo 'Hello World';
}
/**
* @return testService
*/
private function getTestService() {
return InitPHP::getService('test','test');
}
}
可以检测提交过来的TOKEN是否正确,正确返回TRUE,错误返回FALSE。可以设置是否必须POST方式提交,InitPHP建议采用POST方式提交。在Controller中使用
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
if ($this->controller->check_token() == false) {
exit('Token 不正确,不能提交数据');
}
$this->view->display(); //模板显示
}
public function test() {
echo 'Hello World';
}
/**
* @return testService
*/
private function getTestService() {
return InitPHP::getService('test','test');
}
}
TOKEN,每个用户登录后都会生成一个随即TOKEN,只有拿着这个TOKEN才可以在网站上进行正常访问。在GET和POST提交数据的地方都需要带上TOKEN,可以防止CSRF攻击,提高网站安全性。TOKEN会自动生成。在Controller中使用
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
echo $this->controller->get_token(); //获取TOKEN
}
public function test() {
echo 'Hello World';
}
/**
* @return testService
*/
private function getTestService() {
return InitPHP::getService('test','test');
}
}
重定向函数,可以自定义重定向URL和跳转的时间。在Controller中使用
| 参数 | 类型 | 是否必须 | 描述 |
|---|---|---|---|
| $url | String | 是 | URL |
| $time | Int | 否 | 重定向时间 |
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$this->controller->redirect('http://www.baidu.com', 3); //3秒后跳转到百度
}
public function test() {
echo 'Hello World';
}
/**
* @return testService
*/
private function getTestService() {
return InitPHP::getService('test','test');
}
}
返回http404。在Controller中使用
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$this->controller->return404()
}
}
返回http200。在Controller中使用
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$this->controller->return200()
}
}
返回http500。在Controller中使用
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$this->controller->return500()
}
}
返回http403。在Controller中使用
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$this->controller->return403()
}
}
返回http405。在Controller中使用
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
$this->controller->return405()
}
}
验证Service返回的结构是否正确。在Controller中使用
class indexController extends Controller {
public $initphp_list = array('test');
public function run() {
if ($this->controller->check_service_return($ret)) {
return true;
} else {
return false;
}
}
}