yii2

How to display action button as dropdown in Yii2 gridview?

笑着哭i 提交于 2019-12-21 20:33:44
问题 I would like to display action button as dropdown in Yii 2 gridview. How can I achieve that without using any extension? I have added the source code bellow- <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'id', 'name', ['class' => 'yii\grid\ActionColumn', 'template'=>'{view}{update}{delete}', 'buttons' => [ 'view' => function ($url, $model) { return Html::a('<span class="glyphicon glyphicon-eye-open">

Yii2 Override find() to add default condition globally

眉间皱痕 提交于 2019-12-21 19:44:37
问题 I have to override the method using namespace common\models; use Yii; use yii\db\ActiveQuery; class Addfindcondition extends ActiveQuery { public function init() { $this->andOnCondition([$this->modelClass::tableName() . '.branch_id' => Yii::$app->user->identity->branch_id ]); parent::init(); } } And call the method in each model separately like this public static function find() { return new Addfindcondition(get_called_class()); } Now I want to override the find method globally. How it is

Static functions are bad - but what's the alternative?

非 Y 不嫁゛ 提交于 2019-12-21 18:31:48
问题 In my example I'm using the PHP framework Yii2 but I think this applies to most OO languages. I have an ActiveRecord base class which most of my business objects extend from e.g. Project . At the moment if I want a Project instance I call Project::findOne(['id' => $id]); findOne is a static method of ActiveRecord (which is part of the Yii2 framework). So this is bad form because I can't easily mock/stub the return of this call when writing unit tests. But what's the best way to get around

yii2 ActiveRecord findBySql - Response content must not be an array Error

爱⌒轻易说出口 提交于 2019-12-21 17:37:01
问题 New to Yii2 nuances. Just trying to get a return from a ActiveRecord query. I realize there is probably a much easier way to do this using Yii2 conventions public function actionGet_permissions() { $sql = 'select * from auth_item where owner_user_id IS NULL'; return Auth_Item::findBySql($sql)->all(); } Errors "Response content must not be an array." I think its pretty obvious the simple set of records I'm trying to return with this function. Any help is much appreciated, and let me know if

yii2 - how to set currency decimal value

有些话、适合烂在心里 提交于 2019-12-21 16:17:11
问题 I want my currency to ignore decimal value, so far I have this: main.php: 'formatter' => [ 'class' => 'yii\i18n\Formatter', 'thousandSeparator' => '.', 'decimalSeparator' => ',', 'currencyCode' => '€', ], view: [ 'attribute' => 'Score', 'format' => 'currency', ], Any idea on how to move forward? 回答1: The manual on currencyCode : The 3-letter ISO 4217 currency code indicating the default currency to use Try setting currencyCode to 'EUR' (though that doesn't seem to be that important) and put

Installing Yii 2 demo application

和自甴很熟 提交于 2019-12-21 15:20:51
问题 i am trying to install yii 2 and to run the basic or advanced application. i have tried the steps given here Setting up preview of Yii2 to do this. the steps i followed, 1 - Installed the composer 2 - Use composer to install the app alongwith dependencies(Yii): php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial 3 - Access app from http://localhost/my_yii2_trial/web The problem is, i am getting this syntax error. Parse error: syntax error, unexpected

Create a CRUD from a database view using Gii in Yii2

寵の児 提交于 2019-12-21 12:58:51
问题 I have generated a Model using gii of a mariadb view, which worked. Then trying use the gii CRUD generator for the model, I get the error The table associated with app\models\Future must have primary key(s). Which is perfectly understandable as the the view does not have a PK. I found some advice that says to add a primaryKey function to the model so I tried public function primaryKey() { return 'id'; } With id being the column name which is actually the PK in the underlying table, which is

why do i get PHP fatal error when i want to install an extension

我的未来我决定 提交于 2019-12-21 12:17:35
问题 $php composer.phar require "kartik-v/yii2-password": "@dev" Error msg: Call to undefined method Fxp\Composer\AssetPlugin\Package\Version\VersionParser::parseLinks() in /home/john/.composer/vendor/fxp/composer-asset-plugin/Repository/VcsPackageFilter.php on line 272 When i wanna add an extension in my project i got this error, help me to solve it. 回答1: You should delete composer asset plugin : Linux : rm -rf ~/.composer/vendor/fxp Windows : rm -r %APPDATA%\Composer\vendor\fxp And re-install it

Yii2 pretty URL: automatically convert everything with slashes (including all parameters)

寵の児 提交于 2019-12-21 12:14:08
问题 I'm working with Yii2 and I would like to use urlManager with routing to convert all non-letter and non-number characters into slashes. I have looked at a lot of question what have already been asked (#1, #2, #3, #4) but none solved it since they either show a little similar but not what I want or not working for me at all. I have simple urlManager rules: //... 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => array( '

Updating composer throws exception Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist

落爺英雄遲暮 提交于 2019-12-21 07:50:32
问题 I recently ran latest composer installation for a Yii2 basic application template. But running php composer.phar install throws this exception: Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist The "yiisoft/yii2-composer" plugin requires composer-plugin-api 1.0.0, this WIL L break in the future and it should be fixed ASAP (require ^1.0 for example). [ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist [ErrorException] Declaration of