yii2

Yii2: How to let ActiveRecord models only see certain database data?

99封情书 提交于 2019-12-25 03:07:49
问题 I'm trying to implement a multi-tenant application. I have different customers that are using the same code. But each customer gets its own entry script with its own configuration. The customer id is accessible by Yii::$app->params['customerId'] . Note: I have to distinguish the customers that way because there is no login/authentication. Anyway, assume the controller action is called and a customer id is given with the parameter. Now I have some tables and each has a column for the customer

How to custom input field in yii2?

余生颓废 提交于 2019-12-25 02:57:16
问题 Here is yii2 code: <?php $form = ActiveForm::begin([ 'options' => [ 'id' => 'category_id', 'class' => 'mws-form wzd-validate']]); ?> <?= $form->field($model, 'name') ?> <?php ActiveForm::end(); ?> And output HTML: <form id="cat_form" class="mws-form wzd-validate" action="/text/backend/web/index.php?r=cat%2Fcreate" method="post"> <input type="hidden" name="_csrf" value="ZHAzcENzcUI.PEofNCkdNVU7bDslOj4XIUAEFHsDNjUsRVgocUQVCw=="> <div class="mws-form-row"> <div class="form-group field-cat-name

Enable debugger tool for particular user through custom controller in Yii2

可紊 提交于 2019-12-25 02:26:21
问题 To enable debugger tool, we modify web/index.php file defined('YII_DEBUG') or define('YII_DEBUG', false); defined('YII_ENV') or define('YII_ENV', 'prod'); How to override or change these variables in custom controller? class CommonController extends Controller { public function init() { $user_id = 1; if($user_id == 1){ defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); } } } Goal is to enable the debugger for particular user. I know there is a

How to fix Yii2 Contact Widget Problem on View Pages

南笙酒味 提交于 2019-12-25 00:24:20
问题 I followed the example here Yii2, feedback form in a modal window and I was able to create a contact widget that I added it above the footer of multiple pages on my website using the code <?= FBFWidget::widget([]) ?> . I stripped the code of the modal box so I am not using that. The problem I am facing now is that whenever I opened a webpage, the page jumps straight to the contact form at the footer instead of showing the top of the page as a any normal browser should do. I followed all the

How to use two namespaces in one file yii2?

我的未来我决定 提交于 2019-12-25 00:18:48
问题 How can use two namespaces in one file yii2? I need to use namespace backend/controllers; namespace MongoDb; 回答1: You can achieve it like this: <?php namespace backend/controllers; { /* Code goes here */ } { /* Some more code */ } namespace MongoDb; { /* Code goes here */ } { /* Some more code */ } ?> http://php.net/manual/en/language.namespaces.definitionmultiple.php 来源: https://stackoverflow.com/questions/48678794/how-to-use-two-namespaces-in-one-file-yii2

yii2 render after post-request

别等时光非礼了梦想. 提交于 2019-12-24 23:45:47
问题 I have a view with a gridview with checkboxcolumn and a google-map (2amigos). The user selects the machines to display in the map by selecting the corresponding items in the gridview. A html-button submitts the selected keys to the controller. Following the controler code (dataProvider gets updated by post-request): //some code before render $dataProvider = new ActiveDataProvider(['query'=>$query, 'pagination'=>false]); return $this->render('locating', [ 'model' => $model, 'searchModel' =>

Yii2 : Converting a raw query into ActiveRecord

别等时光非礼了梦想. 提交于 2019-12-24 23:41:29
问题 I have a query which goes into this way. select t.id, t.ad_id, sum(t.impression) total_impression, sum(t.view) total_views, sum(t.clicks) total_clicks, t.publisher_id, i.budget, i.name_of_campaign from (select id, ad_id, max(impression) impression, max(view) view, max(clicks) clicks, visitor_ip, publisher_id from ad_analytics group by ad_id, visitor_ip) t inner join inventory i on i.id = t.ad_id group by t.ad_id; I want to convert the same for yii2. The query which I have written is. //For

Yii2 isnewrecord generates exception

怎甘沉沦 提交于 2019-12-24 23:03:56
问题 In yii2 set-up I have multiple models - one being one to many with repeat fields in form where I can edit fieldset or add new records. but I am facing issue of duplicate key error. To overcome the same I am trying this code: try{ $userchild->save(); } catch(\Exception $e){ $userchild->isNewRecord = false; $usrchild->save(); } but I am getting the exception: Unknown Method – yii\base\UnknownMethodException Calling unknown method: app\controllers\UserController::setIsNewRecord() What I am

Best way to implement grid with many columns

依然范特西╮ 提交于 2019-12-24 21:19:53
问题 I would like your opinion / knowledge about a situation I have: I have a Mysql table with approximately 50 columns (where the user can filter whether or not the client has multiple products, etc). And currently I only display 10 columns, and the other filter options are optional. I would like a way to display as many columns as possible so that users can perform the desired filters (they are accustomed to filtering in Excel). I had thought about leaving the Associated column always visible,

Yii2 filter on related model where relation name is lower camelCase

十年热恋 提交于 2019-12-24 20:45:43
问题 I've successfully been working through implementing http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview/. Which has been working fine where my relation name is just a single word. But where my relation name is something like subSector I'm getting: Column not found: 1054 Unknown column 'subSector.sub_sector' in 'where clause' . public function search($params) { $query = Product::find(); // add in relation to be able to search with $query-