yii2-advanced-app

Yii2- Unable to upload image

↘锁芯ラ 提交于 2019-12-02 01:44:28
I am working on yii2 . In one of my view, I am trying to upload an image. But I am unable to upload it. Model class MeterAcceptanceHeader extends \yii\db\ActiveRecord { public static $status_titles =[ 0 => 'Prepared', 1 => 'Created', 2 => 'Printed', 3 => 'Canceled', ]; /** * @inheritdoc */ public static function tableName() { return 'meter_acceptance_header'; } /** * @inheritdoc */ public function rules() { return [ [['sub_div', 'prepared_by'], 'required'], [['prepared_by', 'updated_by'], 'integer'], [['prepared_at', 'updated_at'], 'safe'], [['sub_div', 'meter_type', 'status'], 'string', 'max'

Override Yii2 assetManager config in controller

时光总嘲笑我的痴心妄想 提交于 2019-12-01 22:55:55
问题 I use yii-jui to add some UI elements in the views such as datePicker. In the frontend\config\main-local.php I set the following to change the theme used by the JqueryUI: $config = [ 'components' => [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => 'gjhgjhghjg87hjh8878878', ], 'assetManager' => [ 'bundles' => [ 'yii\jui\JuiAsset' => [ 'css' => ['themes/flick/jquery-ui.css'], ], ], ], ], ]; I tried the

Count all record in table in yii2 without where clause

白昼怎懂夜的黑 提交于 2019-12-01 22:38:44
I want to count all record from table without specify any condition : now, i am doing by this way $result['cms'] = Cms::find()->where([])->count(); and it will give me result,but i don't want to use where clause. So how to count all records without where clause. Thank you You can see this doc http://www.yiiframework.com/doc-2.0/yii-db-activequery.html simply using count(): returns the result of a COUNT query. Cms::find()->count(); all(): returns an array of rows with each row being an associative array of name-value pairs. Cms::find()->all(); see this guide for more http://www.yiiframework.com

Override Yii2 assetManager config in controller

懵懂的女人 提交于 2019-12-01 21:08:11
I use yii-jui to add some UI elements in the views such as datePicker. In the frontend\config\main-local.php I set the following to change the theme used by the JqueryUI: $config = [ 'components' => [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => 'gjhgjhghjg87hjh8878878', ], 'assetManager' => [ 'bundles' => [ 'yii\jui\JuiAsset' => [ 'css' => ['themes/flick/jquery-ui.css'], ], ], ], ], ]; I tried the following to override this configuration item in the controller actions method: public function

Yii2: Replace default confirmation message used by Gridview with Sweet alert

♀尐吖头ヾ 提交于 2019-12-01 20:37:27
I am using yii2mod/yii2-sweet-alert in my projects, I am using it on basic and advanced themes, and I love it. The question. How can I change the grid default confirmation dialog that is a plain javascript confirmation in order to use Sweet-alert to make it look better? I already tried modifying the button's template for the delete, because if you want to change the message you will do the following: [ 'class' => ActionColumn::className(), 'template' => '{update}{delete}', 'buttons' => [ 'delete' => function($url, $model){ return Html::a('<span class="glyphicon glyphicon-trash"></span>', [

Deploying Yii2 app to shared host steps

孤者浪人 提交于 2019-12-01 17:41:19
问题 I find it bizarre that there is so little, (if any) details on considerations for deploying a Yii2 app to a shared host server. Does anyone have some steps, tips, considerations for this ? Is there a process you follow that keeps issues/errors down to a minimum ? How does the DB get migrated (with data)? I'm assuming I could do export/import of the DB, copy the Yii app folder directly, but that seems too simplistic ? 回答1: First read this page http://www.yiiframework.com/doc-2.0/guide-tutorial

Yii2 cors filters error that No 'Access-Control-Allow-Origin' header is present

走远了吗. 提交于 2019-12-01 03:04:39
Following This question i have set my rest controller behaviour as public function behaviors() { $behaviors = parent::behaviors(); $auth= $behaviors['authenticator'] = [ 'class' => HttpBearerAuth::className(), 'only' => ['dashboard'], ]; $behaviors['contentNegotiator'] = [ 'class' => ContentNegotiator::className(), 'formats' => [ 'application/json' => Response::FORMAT_JSON, ], ]; $acces=$behaviors['access'] = [ 'class' => AccessControl::className(), 'only' => ['login'], 'rules' => [ [ 'actions' => ['login'], 'allow' => true, 'roles' => ['?'], ], ], ]; unset($behaviors['authenticator']); unset(

Yii2 cors filters error that No 'Access-Control-Allow-Origin' header is present

你说的曾经没有我的故事 提交于 2019-11-30 22:05:18
问题 Following This question i have set my rest controller behaviour as public function behaviors() { $behaviors = parent::behaviors(); $auth= $behaviors['authenticator'] = [ 'class' => HttpBearerAuth::className(), 'only' => ['dashboard'], ]; $behaviors['contentNegotiator'] = [ 'class' => ContentNegotiator::className(), 'formats' => [ 'application/json' => Response::FORMAT_JSON, ], ]; $acces=$behaviors['access'] = [ 'class' => AccessControl::className(), 'only' => ['login'], 'rules' => [ [

Set global language value in Yii2 application

随声附和 提交于 2019-11-30 11:48:49
Where can I set language (based on user's cookie) globally? How to make it work in the whole application (controllers,views, etc.) ? In documentation I found \Yii::$app->language = ''; but, where I can write my logic to change the language in right way? You should use \Yii::$app->language = ''; inside the controller that is parent to all your controllers. The parent class should be inside the components folder, and if it is not available than create the component with something like use yii\web\Controller; class MyController extends Controller { public function init() { parent::init(); #add

YII2 : Add Dynamic form fields and their validations

血红的双手。 提交于 2019-11-30 08:25:24
问题 I am adding dynamic form fields onChange of dropdown. Both types of fields are coming from different models and go to the database in different tables. I have already defined validation rules in models. But validation are not working properly. My code is as follows: Model : <?php namespace common\models; use Yii; /** * This is the model class for table "{{%membership_features}}". * * @property integer $id * @property string $title * @property string $type * @property integer $is_new *