yii2

Yii2 dependency custom rule validation

守給你的承諾、 提交于 2019-12-08 09:31:26
问题 I have two input fields consider A and B , now i want to validate that user can input at least one field that is either A or B field. Is there a way to create a rule condition? 回答1: Add like this in rules public function rules() { return [ [['field_A'],'required','when' => function($model) { return $model->field_B == NULL; }, 'message' => 'Either field_A or field_B is required.'], [['field_B'],'required','when' => function($model) { return $model->field_A == NULL; }, 'message' => 'Either

Undefined Variable :value in _form in yii2

半城伤御伤魂 提交于 2019-12-08 09:01:10
问题 I need to add a textfield which does not belong to the model. So I've added the following code in the form <?= Html::textInput("totaldays", $value) ?> Please tell me how to declare this variable or how can I resolve this. I've tried adding public $value; in the model. But the error remains. Please help. Controller public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), 'totaldays' => $value, ]); } view.php <?php use yii\helpers\Html; use yii\widgets

How to set up different document roots on OpenShift for Yii2 advanced template

天大地大妈咪最大 提交于 2019-12-08 08:59:41
问题 After I use the Yii2 advance template (https://github.com/yiisoft/yii2-app-advanced) it needs different documents roots for frontend and backend. Set document roots of your Web server: for frontend /path/to/yii-application/frontend/web/ and using the URL http://frontend/ for backend /path/to/yii-application/backend/web/ and using the URL http://backend/ In my local machine I have set up apache and configured the virtual host to have an alias to point to backend. <VirtualHost ..:80>

YII2: How can I create a link/url in a Menu item to point to an external webpage instead of an action or view of my application

雨燕双飞 提交于 2019-12-08 08:10:39
问题 I am using the YII2 Menu Widget and did not find the solution to add attribute options like class , target on created link. My code is below: echo Menu::widget( [ 'options' => [ 'class' => 'sidebar-menu' ], 'items' => [ [ 'label' => Yii::t('backend', 'Admin'), 'url' => Yii::$app->homeUrl, 'icon' => 'fa-list-alt', 'options' => [ 'class' => 'treeview', ], 'items' => [ [ 'label' => Yii::t('backend', 'External link'), 'url' => 'http://google.com', 'icon' => 'fa-list-alt', 'options' => [ 'target'

Cant use tockens and extrapattern together for REST services in Yii2

和自甴很熟 提交于 2019-12-08 07:17:00
问题 Yii2 REST query I found this for using custom action in the controller for that i added the extrapattern mentioned in the above link And its working fine when we search .but cant use the normal actions for the controller 'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ [ 'class' => 'yii\rest\UrlRule', 'controller' => 'v1/country', 'extraPatterns' => [ 'GET search' => 'search' ], 'tokens' => [ '{id}' => '<id:\\w+>' ] ] ], ]

yii2 basic multiple language

我是研究僧i 提交于 2019-12-08 07:06:57
问题 I need to make website with 2 languages in Yii2 basic framework, however, I researched tons of times on google and other search engines and I could only find yii2 advanced internalisation. I need for basic mode, please if you have source codes for yii2 basic multiple languages or if you know any link or video tutorial about yii2 basic internalisation, please kindly share with me, I would be greatly appriciated. I am looking forward from hearing from you soon. 回答1: The best tutorial is

Yii2 GridView checkbox apply selected class

别等时光非礼了梦想. 提交于 2019-12-08 06:15:05
问题 How it is possible to apply selected class on Yii2 Gridview rows,when checkbox selected. GridView::widget([ 'tableOptions' => ['class' => 'table table-striped table-hover'], 'dataProvider' => $dataProvider, 'layout' => "{items}<div class='row'><div class='pull-left'> \n {summary}</div><div class='pull-right'>{pager}</div></div>", 'columns' => [ // ['class' => 'yii\grid\SerialColumn'], [ 'class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => function($model, $key, $index, $column) { return

Migrating Yii2 from Apache to Nginx - failed on backend app

寵の児 提交于 2019-12-08 05:34:29
问题 I try to move my Yii2 app from using apache to nginx. I'm using Yii2 advanced template on a single domain, so I follow the solution from this link creating a symlink from frontend/web to the backend/web . This solution works fine when I'm using apache, but when I try to use nginx I can't open the backend app. The frontend app works fine, but when I try to open the backend app using app.local/belakang , it is redirected to app.local/belakang/site/login , but still stuck in the frontend app and

How to use Yii2 Sluggable Behavior?

巧了我就是萌 提交于 2019-12-08 05:24:54
问题 I have defined this behavior as per documentation instructions. public function behaviors() { return [ TimestampBehavior::className(), [ 'class' => SluggableBehavior::className(), 'attribute' => 'title', ], ]; } In my config url manager I have defined custom rule like this: example.com/article/1 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ 'article/<id:\d+>/<slug>' => 'article/view', ], ], My view action is: public

Htaccess Yii 2 Configuration

Deadly 提交于 2019-12-08 04:50:45
问题 I am working on a Yii2 Project and have set it up on Wamp Localhost. My Wamp I have set up an alias: Alias /project "c:/Users/Shaun/Desktop/projects/project/web/" <Directory "c:/Users/Shaun/Desktop/projects/project/web/"> AllowOverride all </Directory> In a basic app I have placed the htaccess file into the web directory (where it is currently pointing to) project/web/.htaccess project/web/index.php project/web/index-test.php mod_rewrite is definitely enabled I have checked. I can navigate to