コード例 #1
0
 public function run()
 {
     $models = Categories::getDb()->cache(function ($db) {
         return Categories::find()->alias('Main')->andWhere(['Main.parent_id' => $this->_parentId])->active('Main')->orderBy('Main.group, Main.title')->all();
     });
     return $this->render($this->view, ['models' => $models]);
 }
コード例 #2
0
 public function up()
 {
     $this->addColumn('categories', 'alias', $this->string());
     $this->createIndex('alias_unq_idex', 'categories', 'alias', true);
     $categories = \stronglab\productcatalog\models\Categories::find()->all();
     foreach ($categories as $model) {
         $model->save();
     }
 }
コード例 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categories::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'active' => !is_null($this->active) && $this->active !== 0 ? $this->active : Categories::ACTIVE_ON, 'parent_id' => $this->parent_id, 'category_local_id' => $this->category_local_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
コード例 #4
0
 public function parseRequest($manager, $request)
 {
     if (trim($request->getPathInfo(), '/') == $this->route && $request->get('id') && Categories::findOne($request->get('id'))) {
         header("Location:" . \Yii::$app->urlManager->createUrl([$this->route, 'id' => $request->get('id')]), true, 301);
         exit;
     }
     preg_match($this->pattern, \Yii::$app->request->getPathInfo(), $matches);
     $matches = $this->substitutePlaceholderNames($matches);
     $root = explode('/', trim($request->getPathInfo(), '/'));
     if (!isset($matches['parent'], $matches['alias']) && isset($root[1])) {
         $matches['alias'] = $root[1];
     }
     if (!isset($matches['alias'])) {
         return parent::parseRequest($manager, $request);
     }
     $model = Categories::findOne(['alias' => $matches['alias']]);
     if (!$model) {
         return parent::parseRequest($manager, $request);
     }
     if (isset($matches['parent']) && !Categories::findOne(['alias' => $matches['parent']])) {
         throw new NotFoundHttpException('Страница не найдена');
     }
     return [$this->route, ['id' => $model->id]];
 }
コード例 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategories()
 {
     return $this->hasMany(Categories::className(), ['id' => 'category_id'])->viaTable('categories_has_products', ['product_id' => 'id']);
 }
コード例 #6
0
?>

    <?php 
echo $form->field($model, 'farm_price')->textInput()->hint('По умолчанию 150');
?>

    <?php 
echo $form->field($model, 'weight')->textInput()->hint('По умолчанию 15');
?>

    <?php 
echo $form->field($model, 'active')->dropDownList(\stronglab\productcatalog\models\Products::$activeText);
?>

    <?php 
if ($categories = Categories::getDropDown()) {
    ?>

        <?php 
    echo $form->field($model, 'categories')->widget(MultiSelect::classname(), ['options' => ['multiple' => 'multiple', 'encode' => false], 'data' => $categories]);
    ?>
    <?php 
}
?>
    <?php 
echo $form->field($model, 'upload_files[]')->widget(FileInput::classname(), ['options' => ['multiple' => true], 'pluginOptions' => ['uploadUrl' => \yii\helpers\Url::toRoute(['/catalog/products/upload']), 'uploadExtraData' => ['model_id' => $model->id, 'category' => 'products'], 'showUpload' => false, 'initialPreviewShowDelete' => true, 'maxFileCount' => 10, 'layoutTemplates' => ['actionUpload' => ''], 'initialPreview' => $a(), 'initialPreviewConfig' => $b(), 'overwriteInitial' => false, 'allowedFileTypes' => ['image']]]);
?>

    <?php 
echo Hook::render($model, 'PRODUCT_FORM');
?>
コード例 #7
0
?>

    <?php 
\vova07\imperavi\Widget::widget(['model' => $model, 'attribute' => 'description', 'settings' => ['lang' => 'ru', 'minHeight' => 200, 'plugins' => ['fontsize', 'fontcolor', 'fontfamily']]]);
?>

    <?php 
echo $form->field($model, 'properties')->textarea(['rows' => 6]);
?>

    <?php 
\vova07\imperavi\Widget::widget(['model' => $model, 'attribute' => 'properties', 'settings' => ['lang' => 'ru', 'minHeight' => 200, 'plugins' => ['fontsize', 'fontcolor', 'fontfamily']]]);
?>

    <?php 
echo $form->field($model, 'parent_id')->dropDownList(Categories::getDropDown(), ['prompt' => 'Выберите родительскую категорию']);
?>

    <?php 
echo $form->field($model, 'active')->dropDownList(Categories::$activeText);
?>

    <?php 
echo $form->field($model, 'meta_title')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'meta_description')->textInput(['maxlength' => true]);
?>

    <?php 
コード例 #8
0
 /**
  * Finds the Categories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Categories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategories()
 {
     return $this->hasMany(Categories::className(), ['parent_id' => 'id'])->active()->orderBy('title');
 }