/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CategoryGallery::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(['category_id' => $this->category_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function getCategoryName() { return $this->hasOne(CategoryGallery::className(), ['category_id' => 'category_id']); }
use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use app\modules\admin\models\CategoryGallery; /* @var $this yii\web\View */ /* @var $model app\modules\admin\models\Gallery */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="gallery-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'category_id')->dropDownList([ArrayHelper::map(CategoryGallery::find()->all(), 'category_id', 'name')]); ?> <img id="blah" src="/images/gallery/<?php echo $model->images; ?> " alt="Images" style="width:300px; height:300px;padding:5px"/> <?php echo $form->field($model, 'images')->fileInput(['maxlength' => true, 'id' => "imgInp"]); ?> <script type="text/javascript"> function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) {
/** * Finds the CategoryGallery model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CategoryGallery the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = CategoryGallery::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionIndex() { $galleryModel = Gallery::find()->joinWith('category', 'category.category_id = gallery.category_id')->all(); return $this->render('index', ['galleryModel' => $galleryModel, 'categoryModel' => CategoryGallery::find()->all()]); }