public function createLink($name, $original)
 {
     $model = Taxonomy::findOne($original);
     if (empty($name)) {
         $name = $model->name;
     }
     return [$name, Util::getEntityUrl($model)];
 }
Beispiel #2
0
 public function onMenuConfig($event)
 {
     $collection = Taxonomy::find()->sort()->asArray()->all();
     $event->parameters->set($this->id, ["name" => "分类目录", "id" => $this->id, "tree" => NestedSetsTree::generateTree($collection, function ($item) {
         $item["id"] = $item['taxonomy_id'];
         // 这里还是用taxonomy_id的好..不用slug,因为slug很容易被更改
         return $item;
     })]);
 }
 /**
  * Finds the Taxonomy model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param string $id
  * @return Taxonomy the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Taxonomy::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #4
0
<?php 
echo $form->field($model, 'slug');
?>

<div class="form-group field-category-title required">
    <label for="category-parent" class="control-label"><?php 
echo Yii::t('hass', 'Parent category');
?>
</label>
    <select class="form-control" id="category-parent" name="parent">
        <option value="" class="smooth"><?php 
echo Yii::t('hass', 'No');
?>
</option>
        <?php 
foreach (Taxonomy::find()->sort()->asArray()->all() as $node) {
    ?>
            <option
                value="<?php 
    echo $node['taxonomy_id'];
    ?>
"
                <?php 
    if ($parentId == $node['taxonomy_id']) {
        echo 'SELECTED';
    }
    ?>
            ><?php 
    echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;", $node['depth']) . " " . $node['name'];
    ?>
</option>
 /**
  * Get cached tree structure of category objects
  *
  * @return array
  */
 public function getTaxonomytree()
 {
     if ($this->root != null) {
         $countries = Taxonomy::findOne(['slug' => $this->root]);
         $collection = $countries->children()->asArray()->all();
     } else {
         $collection = Taxonomy::find()->sort()->asArray()->all();
     }
     $indexs = TaxonomyIndex::find()->where(["entity_id" => $this->getEntityId(), "entity" => $this->getEntityClass()])->asArray()->all();
     $indexs = ArrayHelper::getColumn($indexs, "taxonomy_id");
     $trees = NestedSetsTree::generateTree($collection, function ($item) use($indexs) {
         $item["checked"] = false;
         if (in_array($item["taxonomy_id"], $indexs)) {
             $item["checked"] = true;
         }
         return $item;
     });
     return $trees;
 }