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

Yii2 relationship hasOne

I have 2 simple models: class Page extends ActiveRecord { public static function tableName() { return 'page'; } public function getPageType() { return $this->hasOne(PageType::className(), ['id', 'page_type_id']); …
Eduardo
  • 1,781
  • 3
  • 26
  • 61
0
votes
0 answers

Yii2: kartik GridView - filter not working if field from 1:n relation is displayed

I have a gridview for a model, displaying an attribute gender and and a field lang_code from 1:n relation language. When I filter for 'female' it displays the 310 females (out of the 600 total entries). If I then clear the filter, 0 entries are…
Mathias
  • 334
  • 3
  • 5
  • 22
0
votes
2 answers

Yii2 Model ViaTable

For simplicity, lets say I have 3 tables: menu, page and a junction table menu_page. So If I want to get all menus which are available for page "home", in the model I defined a relationship: public function getAllMenus() { return…
Eduardo
  • 1,781
  • 3
  • 26
  • 61
0
votes
0 answers

Yii2 uploadfile image from model method beforeSave

i try to upload 4 or less images, the ajax validation do not return any error, but on submit i get the follow: "errors": { "imageFiles": [ "Please upload a file." ] } attr: /** * @var UploadedFile[] */ public $imageFiles; Rules: return…
0
votes
2 answers

Yii2: how to load different model base on user's preference

I have two model loaded when i user loads the page but only one of this model will take information base on user's preference, but my problem is when the user submit the form the two model are submitted and i get an error because the other model…
sam
  • 853
  • 3
  • 19
  • 50
0
votes
1 answer

How to code query-filter in searchModel for Tyniint

in my Searchmodel, I have defined boolean attributes like this: public function rules() { return [[['balkon_vorhanden', 'fahrstuhl_vorhanden'], 'safe']]; } Both attributes are of datatype tyniint(1),respectively boolean. In method…
tklustig
  • 483
  • 6
  • 24
0
votes
0 answers

captcha not working using scenarios in yii2

I am trying to add captcha validation based on scenario, for which I am first retrieving number of failed attempts from database. For which I am using checkattempts() function. Based on the result I am displaying captcha in view and adding scenario…
rji rji
  • 697
  • 3
  • 17
  • 37
0
votes
1 answer

YII2 gridview sort sum of values of two columns

I successfully displayed the 3 columns in the gridview. the attr1, attr2, and the sum of the 2 attributes. attr1 and attr2 are from the database and the 3rd column is their sum. How do I make the sorting and filtering work? Here is the gridview. …
kittycat_13
  • 113
  • 7
0
votes
2 answers

yii2 AcrtiveRecord whereNot

I have a following SQL query which I want to "build" with the ORM of Yii2: SELECT * FROM table WHERE [some conditions] AND (col1 <> 0 OR col2 <> 0) So I want to exclude all results where col1 and col2 equals 0, but I don't want to do this with the…
MiglyCH
  • 49
  • 5
0
votes
1 answer

Yii2 many to many relation. How to select with condition?

There are two models: Dish and Ingredient. They have relation many to many.I need to get Dishes where ingredient_id = 1,2,3. How to do it?
dr Anton
  • 125
  • 1
  • 7
0
votes
1 answer

Yii2 - Not able to receive data from model with conditional query

I am executing below query: $model = ProjectSites::find()->alias('ps')->select(['ps.site_id', 'ps.id', 'c.circle_name', 'iss.issue', 'iss.created_at', 'iss.id']) ->join('INNER JOIN', 'tbl_circle c', 'c.id=ps.circle_id') …
0
votes
1 answer

Yii2: joinWith andFilterWhere with find_in_set

I am trying to convert an SQL query like this select t1.id,t1.form,t1.type, group_concat(t2.department) as departments from appraisal t1 join department t2 on find_in_set(t2.id,t1.dept) group by t1.id into yii2 AppraisalSearch model. I tried…
user7282
  • 5,106
  • 9
  • 41
  • 72
0
votes
2 answers

redirect to previous address "from which form data was submitted" with model in yii2

I have created a widget to render the form in layouts/main.php footer section. This is a widget file named common\widget\SubscriberFormWidget.php
0
votes
1 answer

how to use subquery inside select statement of yii2

I have a query as below. $subQuery = (new Query())->select('is_approved')->from('user_requests')->where(['user_ref_id' => yii::$app->user->id])->andWhere(['AND','project_ref_id = p.project_id']); This is the subquery which I am trying to call in…
rji rji
  • 697
  • 3
  • 17
  • 37
0
votes
1 answer

Data not saved into database yii2

I am trying to insert some data into one of my tables. But I am unable to save it. public static function setupEmail($ref_no,$customer_id,$install_id) { $sql = "SELECT DISTINCT es.`id` AS 'setup_id',es.`user_id` AS 'user_id',u.`email` AS…
Moeez
  • 494
  • 9
  • 55
  • 147