Questions tagged [yii2-model]

Use this tag if your question relates to the Yii2-model-class or one of its descendants.

This tag should be used whenever your question relates to the \yii\base\Model class or one of its descendants like \yii\db\ActiveRecord.

320 questions
0
votes
1 answer

incorrect output while concatenating query based on if condition yii2

I have a query as below $query= (new Query())->select(['title']) ->from('projects') ->join('LEFT JOIN', 'user AS u', 'p.user_ref_id=u.user_id') ->where('p.created_date >=…
rji rji
  • 697
  • 3
  • 17
  • 37
0
votes
1 answer

Trying to get a Property of Non Object in Yii2

I get this above mentioned error when i was trying to write a search and filter query for gridview,here is code: Store Model: Relation public function getStoreNamesCombo(){ return $this->storeName->classId . ' ' . $this->storeName->platformId…
5.1tat
  • 19
  • 1
  • 6
0
votes
1 answer

Yii2 data migration from migration file

My migration file code/value like below but $model->setAttributes( [ 'id' => '1', 'title' => 'Tag test', 'slug' => 'ssds', 'status' => '1', 'is_archived' => '0', 'description' => 'sdsdfsd asfda s fsd fsadfasfdsaf', …
Destroyer.0211
  • 113
  • 1
  • 3
  • 13
0
votes
2 answers

How to use query data for another sql query in yii2

I have a query here: public function SearchExactJob($id) { $connect = \Yii::$app->db; $query = $connect->createCommand(' SELECT job_name FROM job_questions WHERE job_id=:id') ->bindValue(':id':$id) …
jaegyo23
  • 23
  • 1
  • 12
0
votes
2 answers

Add value (ID) from database to an action button in yii2

I am trying to add the ID on an ActionColumn's button that is coming from the database. I have looked for answers but I don't seem to get one right. Here is my code: $dataProvider, …
jaegyo23
  • 23
  • 1
  • 12
0
votes
2 answers

YII2 Show data in view file according to user id

I am working on my collage project in which admin can create Employees(Teachers) and teachers can create students now my problem is that in index and view file any employee can see the total list of students recently added. i want to put condition…
0
votes
1 answer

Yii2 - Model: find where two different dates are in range

I want to select items which are in a range of two different dates (datetime type in Database). In this case want to select all items in range of dateStart and dateEnd. Example table data: id | dateStart | dateEnd ---+------------+-----------+ 3 |…
lin
  • 17,956
  • 4
  • 59
  • 83
0
votes
1 answer

Getting a value from another model Yii2

How do I get a value and make it appear on a dropDownlist on yii2 For example I have 2 models which is hotel guest and service request. I wanna get the hotelguest_id value from its model and store it on a dropdown on the service request. Similar…
noobkoder
  • 87
  • 18
0
votes
2 answers

Yii2: how to order activeRecord relation query by related field?

I want to execute this query: $topics = ForumTopic::find() ->with([ 'lastPost' => function($query) { $query->select(['id', 'ctime']); }, ]) …
Degibons
  • 103
  • 1
  • 1
  • 7
0
votes
1 answer

The "save" method of model class works very long

I have such method in controller, that simple sets value of status field to 0 or 1. public function actionNews_status($id,$status){ $status = ($status==1)?1:0; $number = false; $news = News::findOne($id); if(!is_null($news)){ …
evgeny_s
  • 391
  • 1
  • 6
  • 17
0
votes
1 answer

Yii2 exist validation rule on database transaction

One function in my model use the transaction to save a row in two distinct tables, table_1 and table_2. In table_2 one foreign key refers to table_1.id and the validation rule, auto generate by gii, is type "exist". When I need to save rows the…
0
votes
2 answers

Validate multiple DropDownList yii2

I'm trying validate a multiple dropdownlist, like this: view/form: field($hours, 'hours_id', ['template' => '{label}{input}{hint}{error}'])->dropDownList(Hours::getHierarchy(), ['size' => 10, 'multiple' =>…
Juan.Queiroz
  • 207
  • 1
  • 3
  • 13
0
votes
0 answers

How to prepare grid view columns array using model or controller in yii2?

I am using yii2 grid view widget like below $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], [ 'attribute' => 'name', …
praba
  • 105
  • 1
  • 3
  • 11
0
votes
1 answer

How to create mysql find query with hasmany() cross/opposite relation in yii2

I have below mysql tables: Table1: emp Fields: id, document_ids Table2: documents Fields: id, document_name Example data: Table1 emp …
Rahul Mankar
  • 910
  • 9
  • 17
0
votes
2 answers

Custom Yii2 TimestampBehavior

I have behavior in my model public function behaviors() { return [ [ 'class' => SluggableBehavior::className(), 'attribute' => 'title', // 'slugAttribute' => 'slug', ], [ …
Vitaxxxa
  • 29
  • 5
id document_ids
1