Yii

Yii import or include

一世执手 提交于 2019-12-22 04:45:12
问题 I encountered a problem about importing php files. Why this works: include( Yii::getPathOfAlias( 'ext.payu.payU').'.php' ); but that don't: Yii::import( 'ext.payu.payU'); ? file payU.php: include_once( dirname(__FILE__) . "/sdk/openpayu.php"); //this is a valid path class payU{ } 回答1: Try to do Yii::import('ext.payu.payU', true) because default one-parameter Yii::import() function call means: hey, just add this path to the known aliases list and do not require() it now and you have to do new

yii2: make checkbox to be checked

好久不见. 提交于 2019-12-22 04:36:19
问题 I am using Yii2 framework and I'd like to generate an html code like this <input type="checkbox" id="queue-order" name="Queue[order]" value="1" checked> in a view which uses ActiveForm. I've tried echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => true]); as well as echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => 'checked']); but desired string "checked" does not appear in the generated html code.

Can you run console jobs from yii2-basic?

▼魔方 西西 提交于 2019-12-22 04:33:09
问题 I am aware that Yii2-advanced has the ability to run console jobs (php yii controllername) but I was wondering if the basic app has the same ability? I notice a console.php file in the config folder, but cannot seem to get the jobs to run. If it is possible, can someone give an example - where does the controller go (since I put it in controllers, but I get the message 'Error: Unknown command test' when trying php yii test) Any help appreciated. 回答1: Yes, the same functionality exists in the

Can you run console jobs from yii2-basic?

喜你入骨 提交于 2019-12-22 04:33:08
问题 I am aware that Yii2-advanced has the ability to run console jobs (php yii controllername) but I was wondering if the basic app has the same ability? I notice a console.php file in the config folder, but cannot seem to get the jobs to run. If it is possible, can someone give an example - where does the controller go (since I put it in controllers, but I get the message 'Error: Unknown command test' when trying php yii test) Any help appreciated. 回答1: Yes, the same functionality exists in the

How to do a bulk database insert in Yii2?

拈花ヽ惹草 提交于 2019-12-22 04:10:10
问题 I'm wondering how you go about doing a bulk database INSERT in Yii2 ? For example a normal INSERT I would like so: $sql = $this->db("INSERT INTO some_table(id,my_value) VALUES(:id,:my_value)"); $sql->bindValues([':id' => $id, ':my_value' => $my_value]); $sql->execute(); Now what if I wanted to create a bulk INSERT ? Without binding values you could it something like: foreach ($foo as $bar) { $data_sql .= '(' . $id . ',' "'" . $bar . "')," } $data_sql = rtrim($data_sql, ','); $sql = $this->db(

Yii2 - check if the user is logged in view

淺唱寂寞╮ 提交于 2019-12-22 04:08:44
问题 I am trying to check is the user logged inside my view file, but I keep getting this error: Call to undefined method Yii::app() I tried adding $ before app but the error is still there (this time it is Undefined variable: app ). Is it possible to this is view? This is the code I use the check if the user is logged: <?php if(Yii::app()->isGuest) echo 'User is not logged!'; ?> 回答1: In Yii2 the correct syntax is Yii::$app->user->getIsGuest(); or Yii::$app->user->isGuest; Look at the

how do I delete rows in Yii?

只谈情不闲聊 提交于 2019-12-22 03:51:11
问题 Using Yii, I want to delete all the rows that are not from today. Is my solution ok ? $query = "delete from `user_login_hash` where `day`!='".(date('Y-m-d',time()))."'"; Yii::app()->db->createCommand($query); 回答1: A prettier solution is YourUserModel::model()->deleteAll("day !='" . date('Y-m-d') . "'"); 回答2: Better user PDO parameters and on command you also have to call execute $query = "delete from `user_login_hash` where `day`<> :date"; $command = Yii::app()->db->createCommand($query);

Yii - Modifing html generated by CListView

99封情书 提交于 2019-12-22 01:36:20
问题 I'm using ClistView to display the content of a dataprovider. ClistView is supposed to call a partial view, that will loop for each model. I would like to display something (i.e. a tag) before the first model and something (i.e. a ) after the last model of the pagination. Assume that I have a view (index.php): $this->widget('zii.widgets.CListView', array( 'dataProvider'=>$localDataProvider, 'itemView'=>'_view', // refers to the partial view named '_post' 'summaryText'=>'Sono visualizzati i

Yii框架tips

為{幸葍}努か 提交于 2019-12-22 00:59:40
db组件 'schemaCachingDuration'=>3600, 为什么不起做用? 需要开缓存 如何在页面下边显示sql的查询时间 在log组件的routes中加入 array( 'class'=>'CProfileLogRoute', 'levels'=>'error, warning', ) 同时在db组件中加入 'enableProfiling'=>true, 同时在这种情况下,可以用CDbConnection::getStats() 查看执行了多少个语句,用了多少时间 如何知道某一个程序段运行需要的时间 配置好CProfileLogRoute后,在需要测试的地方加上 Yii::beginProfile('blockID'); //程序段 Yii::endProfile('blockID'); 'enableParamLogging'=>true,的作用是? 在日志的bind的参数后边跟数的值 如何在页面底部显示所有的db相关的日志 同上,配置log组件的routes中加入 array( 'class'=>'CWebLogRoute', 'levels'=>'trace, info, error, warning', 'categories' => 'system.db.*', //'showInFireBug' => true, 将在firebug中显示日志 ),

How does a select2 widget gets populated with AJAX?

China☆狼群 提交于 2019-12-21 22:33:03
问题 When I enter a few characters in my widget, I get results like these from AJAX: [{"id":550,"campName":"IB Resi Showtime Rebate Website"},{"id":60,"campName":"OB ACGBK EB"}] However, I'm missing the part on how to populate the widget with those results. Here is the code I use for the widget: $this->widget ( 'ext.ESelect2-master.ESelect2', [ 'selector'=>'#campaigns', 'options'=> [ 'tags'=>$tags, 'allowClear'=>true, 'minimumInputLength' => 2, 'width'=>'300px', 'multiple'=>true, 'placeholder'=>