示例#1
0
 public function getListViaClass($className = null)
 {
     if (!is_null($className) && class_exists($class = strpos($className, 'Category') !== false ? $className : $className . 'Category')) {
         $type = (new $class())->isWhat();
     } else {
         if (isset($this) && get_class($this) == __CLASS__) {
             $class = __CLASS__;
             $type = $this->isWhat();
         } else {
             $class = __CLASS__;
             $type = $class::isWhat();
         }
     }
     $key = 'list-' . md5($class);
     if (Cache::cache()->exists($key)) {
         return Cache::cache()->get($key);
     } else {
         $ret_val = parent::getList(null, ' ', ['orderBy' => ['name' => SORT_ASC], 'where' => ['type_id' => new \yii\db\Expression("(SELECT id FROM " . $class::tableName() . " WHERE slug='" . $type . "' LIMIT 1)")]]);
         Cache::cache()->set($key, $ret_val);
         return $ret_val;
     }
 }