yii2

what a part does bower/bower-asset play in php application such as yii2

為{幸葍}努か 提交于 2020-01-04 01:50:47
问题 Recently I deployed some projects like trntv/yii2-starter-kit and so on.but all applications are publishing assets on '@vendor/bower' instead of'@vendor/bower/bower-asset'. I have read the question Yii2 Composer manage package in bower and bower-vendor and solved it . but I still feel confused about the directory vendor/bower/bower-asset . What's the part does bower/bower-asset play in php application? it is not a composer package but many theme store in there. Furthermore, bower is a

yii2 behaviors ActiveRecord::EVENT_BEFORE_INSERT not working

自闭症网瘾萝莉.ら 提交于 2020-01-03 21:48:30
问题 My behavior function in my model is as follows public function behaviors() { return [ 'timestamp' => [ 'class' => 'yii\behaviors\TimestampBehavior', 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['log_in_time' ], ActiveRecord::EVENT_BEFORE_UPDATE => ['log_in_time'], ], 'value' => new Expression('NOW()'), ], ]; } /** * validation rules */ public function rules() { return [ ['username','filter', 'filter' => 'trim'], ['username','required'], //['username','unique'], ['username','string'

Yii2 gii crud error Class 'app\models\Yii' not found

左心房为你撑大大i 提交于 2020-01-03 20:56:10
问题 I just installed yii2 advanced template, I created a model News and now I want to create the Crud (with gii), but when I click 'preview' I get this error. I did not change anything else in the advanced template. I'm using wamp PHP Fatal Error – yii\base\ErrorException Class 'app\models\Yii' not found 1. in C:\wamp\www\advanced\backend\models\News.php at line 44 2. in C:\wamp\www\advanced\vendor\yiisoft\yii2-gii\generators\crud\default\search.php – yii\gii\generators\crud\Generator:

add a button to grid view in yii2

↘锁芯ラ 提交于 2020-01-03 20:12:52
问题 i'm a new yii2 developer ! i made a GridView and the code is shown below : <?php Pjax::begin(); ?> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\CheckboxColumn'], ['class' => 'yii\grid\SerialColumn'], 'id', 'countryCode', 'countryName', 'currencyCode', ], ]); ?> <?php Pjax::end(); ?> a screenshot of output : OUTPUT now i want to have a column contain some button and that button

add a button to grid view in yii2

谁说胖子不能爱 提交于 2020-01-03 20:12:16
问题 i'm a new yii2 developer ! i made a GridView and the code is shown below : <?php Pjax::begin(); ?> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\CheckboxColumn'], ['class' => 'yii\grid\SerialColumn'], 'id', 'countryCode', 'countryName', 'currencyCode', ], ]); ?> <?php Pjax::end(); ?> a screenshot of output : OUTPUT now i want to have a column contain some button and that button

Where do I put global Variables in Yii2 similar to YII_DEBUG and YII_ENV

自作多情 提交于 2020-01-03 16:47:42
问题 I'm building a website that has a "subdomain" called marketplace. so the url will be marketplace.sample.com. I'm using the Yii2 advanced application and I added the following code to my index.php located in frontend/web. defined('MARKETPLACE') or define('MARKETPLACE', preg_match('/^marketplace/', $_SERVER['HTTP_HOST']) === 1 ? true : false); This works on my environment, however, I just realized that the index.php file is in the .gitignore file in Yii2 because that file is created by the init

yii2 url not found shown while accessing controller action

∥☆過路亽.° 提交于 2020-01-03 15:55:08
问题 I have created a controller function like public function actionRateTicket($id){ } The urlManager has the following configuration 'urlManager' => [ 'class' => 'yii\web\UrlManager', // Disable index.php 'showScriptName' => false, // Disable r= routes 'enablePrettyUrl' => true,'enableStrictParsing' => true, 'rules' => array( '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/

Getting a “Headers already sent” error in Yii when rendering a view in beforeAction

放肆的年华 提交于 2020-01-03 13:07:02
问题 I've read about Yii2's handlers and I don't grasp how to use them properly for this case. Basically in my SiteController , I have: class SiteController extends \app\components\Controller { public function beforeAction($action) { // Makes some checks and if it's true, will render a file and stop execution of any action if (...) echo $this->render('standby'); return false; } return true; } // All my other actions here } This seems to work well and stop the execution, however I get the "Headers

Yii2: How can I add an JavaScript library via composer?

我与影子孤独终老i 提交于 2020-01-03 10:46:29
问题 I have setup a basic app according to this guide (Installing Yii). This is no problem. According to the guide I have also added fxp/composer-asset-plugin globally to composer.phar. Also no problem. Now I've got the requirement to work with q.js which is hosted* as npm package. But I don't know how to add it via composer. I know I could probably use a CDN instead or download and store it manually. But I prefer using composer. So what do I have to do to make this work? I have added this to my

RESTful response how to return JSON instead of XML in Yii2?

杀马特。学长 韩版系。学妹 提交于 2020-01-03 09:04:25
问题 The problem is that responses from RESTful server in Yii2 come back as XML, and I need them to be in JSON format. I was following the guide from Yii2, the controller looks the same, the model is kind of different, it is connected to a database (the model was previously copied from a default model in an advanced template), and web config is also the same like the guide. Just to clarify any doubts, here is the code: UserController.php <?php namespace app\controllers; use yii\rest