Zhucola

Zhucola

PHP JAVA

  • 财富值800
  • 威望值100
  • 总积分1910

个人信息

  • 赞了回答

    你可以自由选择使用Smarty之类的模板

  • 发布了源码
    yii2-redis 的 Connection 源码分析
  • 发布了源码
    Model 模型底层源码分析
  • 就这点内存,都没有一个phpfpm进程占用的多,不用担心直接搞

  • yii的attributeLabels和attributeHints是这样的

    public function getAttributeLabel($attribute)
    {
        $labels = $this->attributeLabels();
        return isset($labels[$attribute]) ? $labels[$attribute] : $this->generateAttributeLabel($attribute);
    }
    public function getAttributeHint($attribute)
    {
        $hints = $this->attributeHints();
        return isset($hints[$attribute]) ? $hints[$attribute] : '';
    }
    

    但是你的需求是要逆过来
    如果活动记录里面有name字段,你表单传过来的时候username

    //控制器里面
    public function actionModelTest(){
        $model = new TestModel(); //实例活动记录
        $model->username = "test";
    }
    //活动记录里面
    class TestMode extends ActiveRecord{
        
    }
    

    这样的活走的是模式方法get

    public function __get($name)
    {
        if (isset($this->_attributes[$name]) || array_key_exists($name, $this->_attributes)) {
            return $this->_attributes[$name];
        }
        if ($this->hasAttribute($name)) {
            return null;
        }
        if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) {
            return $this->_related[$name];
        }
        $value = parent::__get($name);
        if ($value instanceof ActiveQueryInterface) {
            $this->setRelationDependencies($name, $value);
            return $this->_related[$name] = $value->findFor($name, $this);
        }
    
        return $value;
    }
    

    核心就是hasAttribute方法,会去推到出表结构,然后判断是否存在,
    所以可以重新get魔术方法

    public $attributeMap = [
        "username" => name,
    ];
    public function __set($name, $value){
        if(isset($this->attributeMap[$name])){
            $this->setAttribute($this->attributeMap[$name],$value);
        } else {
            parent::__set($name, $value);
        }
    }
    

    一些yii的源码解析,欢迎star~
    https://github.com/Zhucola/yii_core_debug

  • 2019-07-16 已签到
    连续签到3天,获得了15个金钱
  • 2019-07-15 已签到
    连续签到2天,获得了10个金钱
  • 2019-07-14 已签到
    连续签到1天,获得了5个金钱
  • 2019-07-12 已签到
    连续签到5天,获得了20个金钱
  • 2019-07-11 已签到
    连续签到4天,获得了20个金钱
经理 等级规则
1910/2000
资料完整度
40/100
用户活跃度
0/100

Ta的关注

1

Ta的粉丝

11

Ta的访客

19