zoukankan      html  css  js  c++  java
  • YII学习总结2(命名空间和操作响应)


    YII基础准备
    1.命名空间
    <?php /****假设有三个同名的类,输出的值为A,B,C****/ use acapple; use defapple as bApple; use ghiapple; $app = new apple();//A $app = new bApple();//B $app = new Apple();//C 调用的是全局的

    2.操作响应
    <?php  
    namespace appcontrollers;

    use yiiwebController;
    use yiidataPagination;
    use appmodelsCountry;

    class CountryController extends Controller
    {
    public function actionIndex()//不叫方法叫操作
    {
    $request = YII::$app->request;//能够获取到url值
    echo $request->get('id',20);//如果没有传参可以设置默认值

    if($request->isGet) //isPut
    {
    echo "this is get method";
    }

    echo $request->userIP;//获取用户IP

    $res = YII::$app->response;//获取响应状态
    $res->statusCode = 404;//人为设置响应状态码

    //$res->headers->add('pragma','no-cache');//设置head不设置缓存
    $res->headers->set('pragma','max-age=5');//设置head缓存5分?秒钟
    $res->headers->remove('pragma');

    //跳转
    $res->headers->add("location","http://www.baidu.com");
    $this->redirect("http://www.baidu.com",302);

    //文件下载
    $res->headers->add('content-disposition','attachment;filename="a.jpg"');
    $res->sendFile("robots.txt");

    }
    }
  • 相关阅读:
    UrlPathEncode与UrlEncode的区别
    大文件读取方法(C#)
    JavaScript与FileSystemObject
    ActiveXObject对象详解
    JS获取事件源对象
    实用JS大全
    设计模式的适用场景
    [转载]BigPipe技术
    window.location
    AJAX XMLHttpRequest
  • 原文地址:https://www.cnblogs.com/isuben/p/5502339.html
Copyright © 2011-2022 走看看