yii2

How do I set a default configuration for GridView in Yii2 without the widget factory?

删除回忆录丶 提交于 2019-12-21 07:23:53
问题 This is what a gridview looks like in Yii2: <?php echo GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], ... ['class' => 'yii\grid\ActionColumn'], ], ]); ?> I want change my grids a little bit, so I add this line: tableOptions'=>['class'=>'table table-condensed'], This works great, but... I want this to be the default value for all my grids! In Yii 1, this would look like this: 'widgetFactory' => array(

Yii Framework 2.0 Rules Date Validator

半城伤御伤魂 提交于 2019-12-21 07:15:07
问题 I am using Yii Framework 2.0. I have a form with a text input field which is meant for a date. I have read the Yii Framework 2.0 about the Class yii\validators\Validator and known all the validator keys which can be used inside of the rules() method in a model class. When I use the date key as below, it does not validate anything. It means that I still can put some text in that input field and can post the form. When I changed it into boolean or email , I could see that it validates very well

Redirect to a page other than login in Yii 2 behaviors

前提是你 提交于 2019-12-21 06:57:38
问题 Is there any way to redirect to a page other than login in behaviors method in Yii 2? My behaviors method content: public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], ], ], 'access' => [ 'class' => AccessControl::className(), 'only' => [ 'create','update' ], 'rules' => [ [ 'allow' => true, 'actions' => [ 'create'], 'roles' => ['@'], ], [ 'allow' => true, 'actions' => ['logout'], 'roles' => ['?'], ], ], ], ]; } But it

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

codecept: command not found

﹥>﹥吖頭↗ 提交于 2019-12-21 05:14:13
问题 I did a fresh installation of Ubuntu and after installing Yii2 etc I can't seem to be able to run codecept anymore. I'm using Yii2. I required the latest codecept version in composer.json which is working fine. But I can't seem to find a way to get codeception running again. I've been looking through all the guides but none of them have anything other then just to composer require or add it to the composer.json. I do have noticed when I wanted to add codecept to my $PATH that I don't have a

How to compare Dates from database in Yii2

China☆狼群 提交于 2019-12-21 05:04:32
问题 $time = new \DateTime('now'); $today = $time->format('Y-m-d'); $programs=Programs::find()->where(['close_date' >= $today])->all(); This is code for today's programs whose close_date is greater than today's date . I am getting error: "Invalid Parameter -yii\base\InvalidParamException Operator '1' requires two operands". 回答1: If you want to write where condition as array the code should be like this: $programs = Programs::find()->where(['>=', 'close_date', $today])->all(); Check official

yii2 change controller action in gridview

a 夏天 提交于 2019-12-21 04:46:20
问题 I have ItemController and in actionView I put gridview of my Itempicture, and I want when I click on icon view, update and delete then go to ItempictureController. so How to change controller action in gridview with different controller? 回答1: You need to set $controller property of yii\grid\ActionColumn. In your case, try this: [ 'class' => 'yii\grid\ActionColumn', 'controller' => 'itempicture' ] http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$controller-detail If you are

Yii2 save array of form fields to a single database field

青春壹個敷衍的年華 提交于 2019-12-21 04:41:02
问题 How can I save an array of fields in Yii2 the current/default setup only works for field which aren't array. Below are the form fields I need to save into the single field: <div class="repeat"> <table class="wrapper" width="100%"> <thead> <tr> <td width="10%" colspan="4"><span class="add">Add</span></td> </tr> </thead> <tbody class="container"> <tr class="template row"> <td width="10%"><span class="move">Move</span></td> <td width="10%">An Input Field</td> <td width="70%"> <?= $form->field(

Yii2 RBAC Multiple Assignments for Each User Based on Groups

ⅰ亾dé卋堺 提交于 2019-12-21 04:16:40
问题 My application technically has two areas, a global area (feedback, user profile, user settings, etc) and a group area (contacts, projects, group profile, group settings, etc). I am using the RBAC DBManager for the global area, and it works just fine, but I am having issues implementing an authorization mechanism for the group area. The reason, is that groups can be shared among the users, and a user may have multiple assignments in the group_access table (id, group_id, user_id, item_name) as

yii2 BaseActiveRecord findAll() conditions greater or less than

情到浓时终转凉″ 提交于 2019-12-21 03:42:58
问题 I have country database table (like found in the guide) that I test yii2 development application. I have field population and I want to create a public method in Country model to return all countries of specific population limits. i.e return all countries of population between x and y. I tried the following: // models/Country.php .... public function getPopulationBetween($lower, $upper) { return Country::findAll(['population' => [">=".$lower, "<=".$upper]]); } In the CountryController: public