Yii 2检查yii \ base \ Model中是否存在函数

时间:2014-11-18 11:40:57

标签: php arrays loops yii2

我试图解决标准gii中的cheeking功能问题 我需要检查yii \ base \ Model中是否存在函数 如果存在,请为此函数添加前缀 例如,如果使用yii2 \ gii生成模型 你会有这样的事情

 /**
     * @return \yii\db\ActiveQuery
     */
    public function getErrors()
    {
        return $this->hasMany(Error::className(), ['groupId' => 'id']);
    }

我需要在生成

时更改函数名称
/**
     * @return \yii\db\ActiveQuery
     */
    public function funky_key_getErrors()
    {
        return $this->hasMany(Error::className(), ['groupId' => 'id']);
    }

我扩展了基础知识gii并重写了函数,但它没有帮助 我的代码来自generator \ model \ Generator,我想我需要检查这个函数中的$ relationship

        protected function generateRelations()
            {
\before basik yii code\
            $relations = self::checkExistClass($relations);
            return $relations;
            }

   private static function checkExistClass($relations)
    {
        foreach ($relations as $name => $relation) {
            foreach ($relation as $functionName => $functionValue) {
                $functionNameGet = 'get' . $functionName;
                $directory = new Model;
                if (method_exists($directory, $functionNameGet)) {
                    $relation['funky_key_' . $functionName] = $functionValue;
                    unset($relation[$functionName]);
                }
            }
        }
        return $relations;
    }

0 个答案:

没有答案