yii2

Yii2 How to perform where AND or OR condition grouping?

喜欢而已 提交于 2019-12-17 22:18:37
问题 I am new to Yii-2 framework. How can i achieve following query in Yii-2 framework using activeQuery and models. SELECT * FROM users AS u WHERE u.user_id IN(1,5,8) AND (u.status = 1 OR u.verified = 1) OR (u.social_account = 1 AND u.enable_social = 1) Thanks 回答1: You can try this: //SELECT * FROM users AS u WHERE u.user_id IN(1,5,8) AND (u.status = 1 OR u.verified = 1) OR (u.social_account = 1 AND u.enable_social = 1) $model = arname()->find() ->andWhere(['user_id'=>[1,5,8]]) ->andWhere(['or',

How can I use a simple Dropdown list in the search box of GridView::widget, Yii2?

亡梦爱人 提交于 2019-12-17 22:07:00
问题 I am trying to make a dropdown list in the search box of a GridView::widget , Yii2 for searching related data. So, how can I create a simple dropdown list in the search box of GridView::widget , Yii2 framework? Thanks. 回答1: You can also use below code [ 'attribute'=>'attribute name', 'filter'=>array("ID1"=>"Name1","ID2"=>"Name2"), ], OR [ 'attribute'=>'attribute name', 'filter'=>ArrayHelper::map(Model::find()->asArray()->all(), 'ID', 'Name'), ], 回答2: Add this in Gridview columns array: [

Yii2 routing when using CamelCase action names

主宰稳场 提交于 2019-12-17 19:38:33
问题 If you have say the following controller structure <?php namespace app\controllers; use Yii; use yii\web\Controller; /** * Test controller */ class TestController extends Controller { public function actionMyaction(){ ... //action logic } public function actionMyAction(){ ... //action logic } } The first route can be accessed using the path example.com/test/myaction The second route per Yii 1.x logic should be accessible from the path example.com/test/myAction in Yii2.x routing is using

Yii2 routing when using CamelCase action names

☆樱花仙子☆ 提交于 2019-12-17 19:36:44
问题 If you have say the following controller structure <?php namespace app\controllers; use Yii; use yii\web\Controller; /** * Test controller */ class TestController extends Controller { public function actionMyaction(){ ... //action logic } public function actionMyAction(){ ... //action logic } } The first route can be accessed using the path example.com/test/myaction The second route per Yii 1.x logic should be accessible from the path example.com/test/myAction in Yii2.x routing is using

Yii2: Updating Grid-view using Pjax

限于喜欢 提交于 2019-12-17 19:26:38
问题 Following this Wiki Yii 2.0: Pjax on ActiveForm and GridView - Yii2 I have tried to use my gridview to update on Ajax without page-reload, but couldn't succeed. code of my _form.php <?php $this->registerJs( '$("document").ready(function(){ $("#new_medicine").on("pjax:end", function() { $.pjax.reload({container:"#medicine"}); //Reload GridView }); });' ); ?> <?php use yii\helpers\Html; use yii\widgets\ActiveForm; use kartik\grid\GridView; //use yii\grid\Gridview; use yii\data

Why get Unable to verify your data submission error in Yii2?

ⅰ亾dé卋堺 提交于 2019-12-17 18:15:19
问题 Error: Unable to verify your data submission error Create one public function in Yii2. But, submit data not accept in this method, see following error images. Why is this happen? 回答1: Add this in the head section of your layout: <?= Html::csrfMetaTags() ?> 回答2: If you create the form manually (i.e. without using the yii form methods), you should add an input field like this: <input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken()?>" /> source: http://zero-exception

How to use the swiftMailer in Yii2

 ̄綄美尐妖づ 提交于 2019-12-17 17:32:44
问题 I can't finally understand how to use the swiftMailer extension in Yii2. Judging by that on this subject I didn't find questions, the task is trivial, but up to the end I couldn't understand. There are examples which don't describe in more detail all cycle of sending the letter or I don't understand something :( Setup return [ //.... 'components' => [ ...... 'mail' => [ 'class' => 'yii\swiftmailer\Mailer', 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'localhost', 'username' =>

Yii2 + AngularJS in a single application - how?

假装没事ソ 提交于 2019-12-17 17:27:37
问题 I have experience with both Yii 2 and AngularJS, but separately. I have two questions: Is it possible to use AngularJS in Yii 2's view ? I am asking possible instead of feasible , because I think the problem may have arrived at routing. Also, is it fair enough (for performance) to use Yii 2 and AngularJS together? (Both are MVC so for modular, manageable code.) I searched for a long time, but I was unable to find any proper resource. What is the explanation! 回答1: YES , you can use AngularJS

Install Yii2 extension manually without using Composer

一曲冷凌霜 提交于 2019-12-17 15:28:55
问题 I want to install Select 2 extension widget manually with Yii2 Framework without using composer. I done the following steps but it's not working. 1) Added yii2-widget-select2 to vendor/yii-soft 2) Added following code in my yii-soft/extensions.php : 'yiisoft/yii2-widget-select2' => array( 'name' => 'yiisoft/yii2-widget-select2', 'version' => '2.0.3.0', 'alias' => array( '@yii/kartik' => $vendorDir . '/yiisoft/yii2-widget-select2', ), ), 3) Added display in view form: use kartik\select2

Log the actual SQL query using ActiveRecord with Yii2?

心已入冬 提交于 2019-12-17 10:33:36
问题 I'm doing this: $students = Student::find()->all(); return $this->render('process', array('students' => $students)); and then this in the view: foreach($students as $student) { echo $student->name . ',  '; echo $student->getQuizActivitiesCount(); ?> <br /> <?php } i would like to see the sql query being performed. a student "has many" quiz activities, and the query performs perfectly, but i need to see the raw SQL. is this possible? 回答1: Method 1 With relations that return yii\db\ActiveQuery