fly020212

fly020212

这家伙有点懒,还没写个性签名!

  • 财富值342
  • 威望值100
  • 总积分1582

个人信息

  • 在 控制器 里面 var_dump($this->id, $this->action->id);

    在 视图 里面 var_dump($this->context->id, $this->context->action->id);

  • 默认是没有入口文件的,需要你用 init 脚本初始化

  • 收藏了话题
    页面缓存如何依赖GET参数
  • 直接 $model->load(Yii::$app->request->post()) 或者 $model->attr = Yii::$app->request->post('attrArray')model 里面就可以使用了,如果 model 不方便保存属性的话,也可以用 Yii::$app->request->post('attrArray')model 里面直接访问,

    不清楚是不是你想要的结果

  • /**
     * @param string $id the ID of this controller.
     * @param Module $module the module that this controller belongs to.
     * @param array $config name-value pairs that will be used to initialize the object properties.
     */
    public function __construct($id, $module, $config = [])
    {
        $this->id = $id;
        $this->module = $module;
        parent::__construct($config);
    }
    

    yii 框架需要自己创建 Controller 的实例,你任何时候都不需要覆盖人家的 构造函数,如果你需要覆盖的话,也需要和它的 方法签名 一样,并且调用 parent::__construct99.999% 的情况下,你不需要这么做

    你的问题是,在 controler 初始化的时候,做些验证,用 init() 方法就可以了

  • $config['components']['gii'] 这个位置

    config 目录下,组件配置的文件

  • yii2 下

    如果使用 yii\web\Userlogout 方法的话,默认配置下是会把 session destroy 的

    /**
     * Logs out the current user.
     * This will remove authentication-related session data.
     * If `$destroySession` is true, all session data will be removed.
     * @param boolean $destroySession whether to destroy the whole session. Defaults to true.
     * This parameter is ignored if [[enableSession]] is false.
     * @return boolean whether the user is logged out
     */
    public function logout($destroySession = true)
    {
        $identity = $this->getIdentity();
        if ($identity !== null && $this->beforeLogout($identity)) {
            $this->switchIdentity(null);
            $id = $identity->getId();
            $ip = Yii::$app->getRequest()->getUserIP();
            Yii::info("User '$id' logged out from $ip.", __METHOD__);
            if ($destroySession && $this->enableSession) {
                Yii::$app->getSession()->destroy();
            }
            $this->afterLogout($identity);
        }
    
        return $this->getIsGuest();
    }
    
  • 这个是 php 的基础类型
    http://php.net/manual/en/class.closure.php

  • Response 是有 format 设置的,默认是 const FORMAT_HTML = 'html', Yii2 里面,action 方法可以返回任何类型,但最终会被处理为 Response 类型,在处理输出的过程中,会根据 format 来设置 Content-Type 类型,比如你返回数组,如果此时设置了 formatjson,则返回 json 类型,如果 format 设置为 xml,则返回 xml 类型

    上面的问题,估计是你没有设置 format 属性,并且 action 返回了字符串,所以被当成了 text/html 处理了,可以把 format 设置为 const FORMAT_RAW = 'raw',看下ok不。

    其实 Response 已经有方法能处理文件类型的,public function sendFile($filePath, $attachmentName = null, $options = []), 这个可以自己研究下,我没有测试,只是在源代码中看到的

  • 回复了 的评论

    语言信息 language 变量,放在 cookie 里面是不是会更好一些?

    @小马哥: 我指的并不是技术上的实现,放在 cookie 里面,用户下次来访问的时候,就不需要再次切换到原先选择的语言了,当然对于用户来说,这并没有多少体验上的提升

经理 等级规则
1582/2000
资料完整度
10/100
用户活跃度
0/100

Ta的关注

1

Ta的粉丝

8

Ta的访客

25