yii2-advanced-app

Yii2 theme baseurl

落花浮王杯 提交于 2019-12-24 07:38:38
问题 I'm trying to echo Yii2 theme base url using this official link. <?php $theme = $this->theme; echo $theme->baseUrl; // line 119 ?> but it return me this error : PHP Notice – yii\base\ErrorException Trying to get property of non-object in E:\wamp\www\yii2-app\frontend\views\site\index.php at line 119 Why this error? is it not possible to get Yii2 theme base url? 回答1: seems that you component is not properly defined .. be sure you have a theme defined in you components section eg: return [

How to allow guest access to some actions in Yii2 Controller?

試著忘記壹切 提交于 2019-12-24 03:28:05
问题 I'd like to know how to configure my controller to allow some actions to be executed as a guest and be able to show the view for that guest in Yii2. I've tried this rule in my behaviour 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['create','update'], 'allow' => true, 'ips' => ['127.0.0.1'], ] ], ] Edit: This is the config I tried : 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'actions' => ['create', 'update'], 'roles

How can I get the selected data/item rows in CheckboxColumn Gridview - Yii2

爱⌒轻易说出口 提交于 2019-12-24 02:52:25
问题 I have a problem on getting all the selected values/data Yii2 Gridview using checkboxColumn. I can only get one of the value in the grid using this code: 'class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => function($model, $key, $index, $widget) { return ['value' => $model['item_id'] ]; }, Need some suggestions on how can I get all the values in the grid... Here is my Code Code snippet Controller/View: Controller: public function actionBulk(){ $action=Yii::$app->request->post('action')

Yii2 url manager don't parse urls with get parameter

只谈情不闲聊 提交于 2019-12-24 00:51:22
问题 I've created a module named catalogue with, for the moment, two actions in the default controller: actionIndex actionLineProducts in the index view I have some link which run the line-product's action, the url was the result of: Url::to(['line-products', 'line' => $line->name]) my goal is to obtain a link like catalogue/{line-name} where line-name is the parameter I send to action LineProducts. My urlManager configurations are: 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' =>

Yii2-Use SqlDataProvider with GridView and enable Gridview Filter for search

孤街醉人 提交于 2019-12-23 22:22:09
问题 I am working on yii2 . I have a custom view in which I have placed to views DetailView and GridView . Below is my controller code public function actionViewcreated($id)// passed the id of my model which is created in the previous step { $model=$this->findModel($id); // this will find my model/record based on the id $sub_div = $model->sub_div; $meter_type = $model->meter_type; $query = "SELECT DISTINCT m.`id` AS meter_id, ins.`meter_msn` AS Meter_Serial_Number, ins.`meter_type` AS Meter_Type,

Convert from query to ModelSearch of Yii2

北战南征 提交于 2019-12-23 17:18:47
问题 I'm new in Yii2, and I have a query with right result: SELECT DISTINCT workloadTeam.project_id, wp.project_name, workloadTeam.user_id, workloadTeam.commit_time, wp.workload_type FROM (SELECT p.id, p.project_name, w.user_id, w.commit_time, w.comment, w.workload_type FROM workload as w, project as p WHERE w.user_id = 23 AND p.id = w.project_id) wp INNER JOIN workload as workloadTeam ON wp.id = workloadTeam.project_id But in my ModelSearch.php, I wrote: $user_id = Yii::$app->user->id; $subquery

yii2 - model load function does not set some model attributes

你离开我真会死。 提交于 2019-12-23 17:04:21
问题 I'm working on a PHP Yii2 application. I have a strange problem with yii2 yii\base\Model.load function. Here is my problem: I have a form model called PaymentIncreaseBalanceForm like below: class PaymentIncreaseBalanceForm extends yii\base\Model { public $amount; public $receiptNumber; public $description; ... } Here is part of my view file: <?= $form->field($model, 'amount')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'receiptNumber')->textInput(['maxlength' => true]) ?> <?

how to get post value from multiple array in yii2

本小妞迷上赌 提交于 2019-12-23 16:33:02
问题 I want to get value of post array in yii2, I have array like this [Brand] => Array ( [name] => Array ( [0] => testing [1] => jkhkjhjkhjk ) [tagline] => Array ( [0] => kjhjkh [1] => ) [meta_keyword] => Array ( [0] => [1] => ) [sort_order] => [image] => brand/1452498338552.jpg [status] => ) ) I tried to get value with below function, but i am unable to get it. $request = Yii::$app->request; $request->post('Brand[name][0]'); How can i get value of name array ? I don't want to use it like $_POST[

Using find() in Active Record with multiple where clause

自闭症网瘾萝莉.ら 提交于 2019-12-23 12:00:03
问题 I want to divide (using brackets) following Active Record query in 3 groups. First group would be from first "Where" clause to last "orWhere". Second and third would be using "andWhere". Please give me suggestions about how can I use brackets to separate all 3 sections. $query = Book::find() ->where('book_name LIKE :book_name', array(':book_name' => '%'.$book_name.'%')) ->orWhere('book_category LIKE :book_category', array(':book_category' =>'%'.$category.'%')) ->orWhere('finance_subcategory

Yii2 isGuest giving exception in console application

二次信任 提交于 2019-12-23 10:57:51
问题 In console application when I used Yii::$app->user->isGuest it is giving the below exception: Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown prop erty: yii\console\Application::user' I even tried adding the user in components array in config file. But it didn't worked. Any idea what am I doing wrong? 回答1: In Console application Yii->$app->user does not exist. So, you need to configure user component in config\console.php . like as, config\console.php 'components'