public function actionIndex() { $data = ['categoryName' => '123', 'categoryDescript' => 'ok', 'icon' => '123ok']; Category::addCategory($data); exit; return $this->render('index'); }
/** * Updates an existing Post model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'category' => Category::find()->all()]); } }
public function actionCreate() { $model = new Category(); $roots = ArrayHelper::map(Category::find()->roots()->all(), 'name', 'name'); if ($model->load(\Yii::$app->request->post())) { $post = \Yii::$app->request->post('Category'); if ($post['parent'] == null) { $parent = new Category(['name' => $post['name']]); $parent->makeRoot(); } else { $parent = Category::findOne(['name' => $post['parent']]); $child = new Category(['name' => $post['name']]); $child->appendTo($parent); } } else { return $this->render('create', ['model' => $model, 'roots' => $roots]); } }
public function actionCreate() { $error = ''; $model = new Category(); $data['csrf'] = Yii::$app->request->post('_csrf'); $data['Category'] = Yii::$app->request->post(); if (isset($data['Category']['submit'])) { $data['Category']['create_date'] = time(); $data['Category']['user_create'] = \Yii::$app->user->id; $data['Category']['intro'] = $data['Category']['editor1']; if ($model->load($data) && $model->save()) { return $this->redirect(['index']); } else { $error = $model->getErrors(); return $this->render('create', ['error' => $error]); } } return $this->render('create', ['error' => $error]); }
public function actionNews_second() { if ($_GET['id']) { $id = $_GET['id']; } if ($_GET['pid']) { $pid = $_GET['pid']; } $category_name = \backend\models\Category::findOne(['id' => $pid])->title; $second_name = \backend\models\Category::findOne(['id' => $id])->title; $infos = \common\models\cms\Article::find()->where(['category_id' => $id])->asArray()->all(); return $this->render('news_second', compact("infos", "category_name", "second_name")); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $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; } $query->andFilterWhere(['id' => $this->id, 'parent_category' => $this->parent_category, 'status' => $this->status, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'user_create' => $this->user_create, 'user_update' => $this->user_update]); $query->andFilterWhere(['like', 'nama', $this->nama])->andFilterWhere(['like', 'deskripsi', $this->deskripsi])->andFilterWhere(['like', 'user_by', $this->user_by]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $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; } $query->andFilterWhere(['id' => $this->id, 'title' => $this->title, 'parent_id' => $this->parent_id, 'status' => $this->status]); $query->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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; } $query->andFilterWhere(['id' => $this->id, 'id_difficulty' => $this->id_difficulty, 'id_training' => $this->id_training, 'id_where' => $this->id_where, 'rank' => $this->rank, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'url_official', $this->url_official])->andFilterWhere(['like', 'url_info', $this->url_info])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'name_alternative', $this->name_alternative])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'id_classification', $this->id_classification])->andFilterWhere(['like', 'equipement', $this->equipement])->andFilterWhere(['like', 'images', $this->images])->andFilterWhere(['like', 'author', $this->author]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $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; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $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; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'create_at' => $this->create_at, 'update_at' => $this->update_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'intro', $this->intro]); return $dataProvider; }
public function actionSubcategory() { $view = \Yii::$app->view; $view->params['moduleName'] = '分类管理'; $data['token'] = Token::getToken(); $scid = \Yii::$app->request->_get('id', '0'); $subC = []; if (intval($scid)) { $subC = Category::getSubcategory($scid); } $data['category'] = $subC; $data['scid'] = $scid; $data['token'] = Token::getToken(); $userId = \Yii::$app->user->id; $data['addIdentity'] = EasyHelpers::dataEncrypt('add,' . $userId); $data['modifyIdentity'] = EasyHelpers::dataEncrypt('modify,' . $userId); $data['delcatetwoIdentity'] = EasyHelpers::dataEncrypt('delcatetwo,' . $userId); return $this->render('sub_category', $data); }
use kartik\select2\Select2; /* @var $this yii\web\View */ /* @var $model backend\models\Item */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="item-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'itemname')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'categoryID')->widget(Select2::classname(), ['data' => ArrayHelper::map(Category::find()->all(), 'id', 'name'), 'language' => 'en', 'options' => ['placeholder' => 'Select a state ...'], 'pluginOptions' => ['allowClear' => true]]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
/* @var $model backend\models\News */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="news-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(Category::find()->all(), 'category_id', 'title'), ['promt' => 'Выбрать категорию']); ?> <?php echo $form->field($model, 'images')->fileInput(); ?> <?php echo $form->field($model, 'text')->widget(CKEditor::className(), ['editorOptions' => ['preset' => 'full', 'inline' => false]]); ?> <?php echo $form->field($model, 'date_published')->widget(DatePicker::className(), ['inline' => false, 'language' => 'ru', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-m-d']]); ?> <?php
/** * Finds the CategoryModel model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CategoryModel the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Category::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getCategory() { return $this->hasOne(Category::className(), ['category_id' => 'category_id']); }
public static function getCateory($id) { return Category::find()->select(['id', 'nama', 'parent_category'])->where('id =' . $id)->one(); }
$this->title = 'Kategori'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="category-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Category', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'format' => 'raw', 'value' => function ($model) { return "#" . $model->id; }], 'nama', 'deskripsi:ntext', ['attribute' => 'parent_category', 'format' => 'raw', 'value' => function ($model) { return $model->parent_category != 0 ? Category::getCateory($model->parent_category)->nama : '-'; }], ['attribute' => 'status', 'format' => 'raw', 'value' => function ($model) { return Category::getStatus($model->status); }], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function getCategories() { $categories = Category::find()->where(['deleted' => 0])->all(); return ArrayHelper::map($categories, 'id', 'title'); }
<?php /* @var $this yii\web\View */ use backend\models\Category; use yii\bootstrap\ActiveForm; use yii\helpers\Html; ?> <div class="col-sm-12"> <div class="col-sm-4"> <?php $menus = Category::find()->roots()->all(); $depth = 2; // This will limit to countries & states only for example //$menus->children($depth)->all(); echo '<div id="jstree_demo_div">'; echo '<ul>'; foreach ($menus as $menu) { echo "<li>{$menu->name}"; if (count($menu->children()->all())) { echo "<ul>"; foreach ($menu->children($depth)->all() as $state) { if ($state->depth == $depth) { echo "<ul><li>{$state->name}</li></ul>"; } else { echo "<li>{$state->name}"; } } echo "</ul>"; } /*$countries = Category::findOne(['name' => $menu->name]);
/** * @return \yii\db\ActiveQuery */ public function getIdCategory() { return $this->hasOne(Category::className(), ['id' => 'id_category']); }
']); ?> <?php $model->isNewRecord ? $statusField = 'hidden' : (!empty($sub_categorys) ? $statusField = '' : ($statusField = 'hidden')); ?> <div class="subcategory <?php echo $statusField; ?> "> <?php echo $form->field($model, 'sub_category', ['template' => "{label}{input}\n{hint}\n{error}"])->dropDownList($model->isNewRecord ? [] : ArrayHelper::map($sub_categorys, 'id_level2', 'level2'), ['prompt' => '-- Pilih --']); ?> </div> <?php echo $form->field($model, 'status', ['template' => "{label}{input}\n{hint}\n{error}"])->dropDownList(Category::getStatus(), ['prompt' => '-- Pilih --']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
$this->title = 'Добавление новости'; $breadcrumb = $this->title; } $this->params['breadcrumbs'][] = ['url' => '/news', 'label' => 'Новости']; $this->params['breadcrumbs'][] = $breadcrumb; echo Html::beginTag('div', ['class' => 'col-xs-12']); if (\Yii::$app->session->getFlash('saved', false)) { echo \yii\bootstrap\Alert::widget(['body' => \Yii::$app->session->getFlash('saved'), 'options' => ['class' => 'alert alert-success alert-dismissible']]); } else { if (\Yii::$app->session->getFlash('error', false)) { echo \yii\bootstrap\Alert::widget(['body' => \Yii::$app->session->getFlash('error'), 'options' => ['class' => 'alert alert-danger alert-dismissible row col-xs-10 col-xs-offset-1']]); } } echo Html::endTag('div'); $form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL]); ?> <div class="panel panel-default"> <div class="panel-heading"> <?php echo $this->render('_news_header_buttons', ['model' => $model, 'mode' => $mode]); ?> </div> <div class="panel-body"> <?php echo Html::tag('div', $form->field($model, 'title') . $form->field($model, 'category')->widget(\kartik\select2\Select2::className(), ['data' => ArrayHelper::map(Category::find()->where(['deleted' => 0])->asArray()->all(), 'id', 'title')]) . $form->field($model, 'link')->hint('Оставьте поле пустым, чтобы ссылку сгенерировала система') . $form->field($model, 'text')->widget(\yii\imperavi\Widget::className(), ['id' => 'textEditor', 'options' => ['lang' => 'ru', 'imageUpload' => '/news/upload', 'imageManagerJson' => '/news/uploaded'], 'plugins' => ['imagemanager', 'video', 'border']]) . $form->field($model, 'metaDescription')->textarea() . $form->field($model, 'metaKeywords') . $form->field($model, 'language')->dropDownList($model->getLanguages()) . $form->field($model, 'publishDate')->widget(\kartik\datetime\DateTimePicker::className(), ['pluginOptions' => ['format' => 'dd.mm.yyyy HH:ii']]) . $form->field($model, 'genre')->dropDownList($model->getGenres()) . $form->field($model, 'author'), ['class' => 'col-xs-12']), $form->field($model, 'published', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false), $form->field($model, 'favorite', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false), $form->field($model, 'deleted', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false), $form->field($model, 'moderatedComments', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false), Html::tag('div', Html::button(FontAwesome::i('save') . Html::tag('small', 'сохранить'), ['class' => 'btn btn-app btn-success', 'type' => 'submit']), ['class' => 'text-center']); ?> </div> </div> <?php $form->end(); echo Html::tag('div', '', ['class' => 'clearfix']);
<div class="product-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'product_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'product_price')->textInput(); ?> <?php echo $form->field($model, 'product_category')->dropDownList(ArrayHelper::map(Category::find()->all(), 'category_id', 'category_name')); ?> <?php echo $form->field($model, 'product_description')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'product_slug')->textInput(['maxlength' => true]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?>
public function actionAjaxlihatsubcat() { if (Yii::$app->request->isAjax) { $parent = $_POST['parent']; $id = $_POST['id']; $option = "<option value>-- Pilih --</option>"; if (!empty($parent)) { $category = Category::getCategories($parent, $id); if (!empty($category)) { $cat_id = ''; foreach ($category as $i => $cat) { if ($cat['id_level2'] !== $cat_id) { $option .= "<option value='" . $cat['id_level2'] . "'>" . $cat['level2'] . "</option>"; } $cat_id = $cat['id_level2']; } } } return $option; } }
use kartik\select2\Select2; use yii\bootstrap\Html; use yii\helpers\ArrayHelper; use yii\web\JsExpression; $form = \kartik\form\ActiveForm::begin(['type' => \kartik\form\ActiveForm::TYPE_HORIZONTAL, 'id' => 'edit-rss-form', 'action' => empty($action) ? $model->isNew ? '/rss/add-feed' : '/rss/edit-feed/' . $model->id : $action, 'options' => ['data-pjax' => true, 'class' => 'editRssForm']]); ?> <div class="modal-body"> <?php if (\Yii::$app->session->getFlash('saved', false)) { echo \yii\bootstrap\Alert::widget(['body' => \Yii::$app->session->getFlash('saved'), 'options' => ['class' => 'alert alert-success alert-dismissible']]); } else { if (\Yii::$app->session->getFlash('error', false)) { echo \yii\bootstrap\Alert::widget(['body' => \Yii::$app->session->getFlash('error'), 'options' => ['class' => 'alert alert-danger alert-dismissible row col-xs-10 col-xs-offset-1']]); } } echo $form->field($model, 'name'), $form->field($model, 'description')->textarea(), $form->field($model, 'categories')->widget(Select2::className(), ['options' => ['multiple' => true], 'data' => !$model->isNew ? ArrayHelper::map(Category::find()->select('id, title')->where(['deleted' => 0])->andWhere(['in', 'id', $model->categories])->asArray()->all(), 'id', 'title') : [], 'pluginOptions' => ['ajax' => ['url' => '/categories/get-list', 'data-type' => 'json', 'data' => new JsExpression("function(params){ return {q:params.term} }")]]]), $form->field($model, 'articles')->widget(Select2::className(), ['options' => ['multiple' => true], 'data' => !$model->isNew ? ArrayHelper::map(News::find()->select('id, title')->where(['deleted' => 0])->andWhere(['in', 'id', $model->articles])->asArray()->all(), 'id', 'title') : [], 'pluginOptions' => ['ajax' => ['url' => '/news/get-list', 'data-type' => 'json', 'data' => new JsExpression('function(params){ var data = {q:params.term}, categories = $("#newsfeedform-categories").val(); if(categories !== null && categories.length > 0){ data.excludedCategories = categories;} return data; }')]]]), $form->field($model, 'published')->checkbox([], false), $form->field($model, 'id', ['options' => ['style' => 'display: none']])->hiddenInput()->label(false); ?> </div> <div class="modal-footer"> <?php if (\Yii::$app->request->isAjax) { ?> <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Закрыть</button><?php } ?> <?php echo Html::tag('div', Html::button($model->isNew ? 'Добавить ленту' : 'Сохранить изменения', ['class' => 'btn btn-success', 'type' => 'submit']), ['class' => 'text-center']); ?> </div> <?php $form->end();
/** * @return \yii\db\ActiveQuery */ public function getCategories() { return $this->hasMany(Category::className(), ['id_where' => 'id']); }
use backend\assets\CategoryAsset; use backend\models\Category; /* @var $this yii\web\View */ /* @var $model backend\models\Category */ CategoryAsset::register($this); $this->title = $model->nama; $this->params['breadcrumbs'][] = ['label' => 'Categories', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="category-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'nama', 'deskripsi:ntext', ['label' => 'Parent Category', 'value' => $model->parent_category != 0 ? Category::getCateory($model->parent_category)->nama : 'Not Set'], ['label' => 'Status', 'value' => Category::getStatus($model->status)], 'date_create', 'date_update']]); ?> </div>
public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($this->isNewRecord) { } else { } // $this->_oldTag = $this->tag; $this->user_by = \Yii::$app->user->identity->nama_depan; $this->schedule_date = date('Y-m-d H:i:s', strtotime(str_replace("-", "", $this->schedule_date))); isset($this->author) ? $this->author_name = User::getUser($this->author)->nama_depan : ($this->author_name = NUll); isset($this->categori_id) ? $this->categori_name = Category::getCateory($this->categori_id)->nama : ($this->categori_name = NUll); return true; } else { return false; } }
<div class="article-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(\backend\models\User::find()->asArray()->all(), 'id', 'username')); ?> <?php echo '<label class="control-label">图片</label>'; echo FileInput::widget(['model' => $model, 'attribute' => 'logo', 'pluginOptions' => ['uploadExtraData' => ['album_id' => 20, 'cat_id' => 'Nature'], 'maxFileCount' => 10, 'initialCaption' => $model->logo, "showUpload" => false]]); ?> <?php echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\backend\models\Category::get(0, \backend\models\Category::find()->asArray()->all()), 'id', 'str_label')); ?> <?php echo $form->field($model, 'status')->dropDownList(\backend\models\Article::getArrayStatus()); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'intro')->textarea(['rows' => 6]); ?> <?php
public function getAllCategorys() { $all = \backend\models\Category::find()->all(); return \yii\helpers\ArrayHelper::map($all, 'id', 'title'); }