yii2-model

Trying to get property of non-object in yii2

元气小坏坏 提交于 2020-05-27 06:17:05
问题 I want access to hasMany relation but i get error with this content PHP Notice – yii\base\ErrorException Trying to get property of non-object this is my view : news/index.php <?php foreach($models as $model): ?> <!-- Project One --> <div class="row"> <div class="col-md-2"> <a href="#"> <img class="img-responsive" src="photos/<?=$model->photos->id?>.jpg" alt=""> </a> </div> <div class="col-md-10"> <h4> <div class="row"> <div class="col-sm-8"> دسته بندی:<?= $model->cat->name; ?> </div> <div

Trying to get property of non-object in yii2

六月ゝ 毕业季﹏ 提交于 2020-05-27 06:16:46
问题 I want access to hasMany relation but i get error with this content PHP Notice – yii\base\ErrorException Trying to get property of non-object this is my view : news/index.php <?php foreach($models as $model): ?> <!-- Project One --> <div class="row"> <div class="col-md-2"> <a href="#"> <img class="img-responsive" src="photos/<?=$model->photos->id?>.jpg" alt=""> </a> </div> <div class="col-md-10"> <h4> <div class="row"> <div class="col-sm-8"> دسته بندی:<?= $model->cat->name; ?> </div> <div

Trying to get property of non-object in yii2

試著忘記壹切 提交于 2020-05-27 06:16:09
问题 I want access to hasMany relation but i get error with this content PHP Notice – yii\base\ErrorException Trying to get property of non-object this is my view : news/index.php <?php foreach($models as $model): ?> <!-- Project One --> <div class="row"> <div class="col-md-2"> <a href="#"> <img class="img-responsive" src="photos/<?=$model->photos->id?>.jpg" alt=""> </a> </div> <div class="col-md-10"> <h4> <div class="row"> <div class="col-sm-8"> دسته بندی:<?= $model->cat->name; ?> </div> <div

YII2 gridview sort sum of values of two columns

跟風遠走 提交于 2020-03-18 10:23:41
问题 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. [ 'label' => 'Number of Enquiries', 'value' => function ($model) { return $model->countEnquire + $model->countPhone + $model->countTrial; }, 'enableSorting' => true, ] How add sorting for this column? 回答1: OK, I don't have your full source code to go

yii2 gii CRUD Generator error - Class 'Message' does not exist or has syntax error

主宰稳场 提交于 2020-01-06 19:36:11
问题 I'm creating a basic text only private messaging system for a website using yii2 advanced. I'm using the gii model and CRUD generators but have encountered a problem with the CRUD generation after I have created the model class. I'm wondering whether it might be an issue with the foreign keys on the message table which have a one to many relationship with the users table (i.e. one user can have many messages). When I attempt to run the CRUD generator with- Model Class- Message Search Model

How i can force an yii2 module to use a specific connection for all his models?

这一生的挚爱 提交于 2020-01-05 07:04:15
问题 on a module I have add a component named db where i put, like the main Yii component, the data for database connection, I need in my module use everytime the db specified in his configuration for all models and not the main database connection, how I can do this? 回答1: You have several way eg. using a separated configuration in app/config/main.php eg adding a specific dbMyMod to component config return [ // ... 'components' => [ // ... 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql

Yii2 dropdown multiple selected values

人盡茶涼 提交于 2019-12-23 12:01:48
问题 I used Yii2 multiple selection dropdown , it is working fine at create but not showing me selected values on update! Form: $form->field($model, 'categories[]') ->dropDownList($model->CategoryDropdown, [ 'multiple'=>'multiple' 'class'=>'chosen-select input-md required', ] )->label("Add Categories"); Model: public function getCategoryDropdown() { $listCategory = Category::find()->select('ID,name') ->where(['is_subcategory' => 'Yes']) ->andWhere(['status' => 'active','approved' => 'active']) -

Yii2 display multiple images in gridview row

扶醉桌前 提交于 2019-12-21 06:37:13
问题 I want to display multiple images in a gridviews single row. For example: I have table A, Table B and table C. Table A has my_id. In Table B my_id is the foreign key. Along with my_id it has c_id. Table C has c_id which is in reference in Table B. Table C also has a filepath to display images. in Table A i have my_id as follows: 1, 2, 3, 4, 5, 6. In Table B i have my_id as follows. 1 ,1 ,1 ,2 ,3, 3. In Table B i also have c_id as follows. 1, 2, 3, 4, 5, 6. In table C my c_id's are: 1, 2, 3, 4