yii2

How to have class loaded without using “use” but call it as if I used it

萝らか妹 提交于 2019-12-07 16:26:57
问题 I have studied these 2 sources, but none of those works for me. http://www.yiiframework.com/doc-2.0/guide-concept-autoloading.html Yii2 - How do I AutoLoad a custom class? I have created custom helper class which I want to include in every model, controller and view in my application. I am using Yii2 advanced app version 2.0.11, IDE I am using is PHPStorm QUESTION: What I want to achieve is to not use use keyword at the beggining of every class but still be able to simply call AppHelper:

How can I add conditions to yii2 depends in AppAsset class?

百般思念 提交于 2019-12-07 16:10:32
问题 There are some depends in AppAsset class in Yii2: public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset' ]; Is there any way to add conditions for this depends like I do it with css and js? public $jsOptions = ['condition' => 'lt IE 7']; Or, may be, you know another way to add conditions to bootstrap and yii JS and CSS files? Thanks UPD: I've added to config/web.php: 'components' => [ 'assetManager' => [ 'bundles' => [ 'yii\web\YiiAsset' => [ 'jsOptions' => ['condition' => 'lt

Save Multiple Image Files Using Kartik FileInput Widget

拟墨画扇 提交于 2019-12-07 15:57:23
问题 I am currently using Yii2 PHP framework and Kartik FileInput widget in my system. I have used followed this guide of input file uploads on multiple files but it didn't work in my system. I am currently using MongoDB as my database. Here's my progress so far (original, single upload only): Controller , actionCreate if($model->load(Yii::$app->request->post())) { $model->attachment = UploadedFile::getInstance($model, 'attachment'); if($model->attachment) { $path = 'archive/contact/' . $model-

From Backend to Frontend Yii2 Advanced App

时光怂恿深爱的人放手 提交于 2019-12-07 15:24:35
问题 I'm trying to link some controllers from frontend to backend. After some hours I don't where could be the problem. Backend file: main.php 'urlManager' => [ 'enablePrettyUrl' => false, 'showScriptName' => false, 'baseUrl' => '/backend/web', ], 'urlManagerFrontEnd' => [ 'class' => 'yii\web\urlManager', 'baseUrl' => '/frontend/web', 'enablePrettyUrl' => false, 'showScriptName' => false, ] file: SiteController.php public function actionIndex() { // User's variable $user = \common\models\User:

Yii2: not able to update column value by + 1

巧了我就是萌 提交于 2019-12-07 14:44:47
问题 I need to update column value by + 1 when new records get created : public function actionCreate() { $model = new CreateBookings(); if ($model->load(Yii::$app->request->post())) { Yii::$app->db->createCommand("UPDATE room_types SET total_booked = total_booked + 1 WHERE room_type = '$model->room_type' ")->execute(); $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } } What am I doing wrong please guide :) 回答1

yii2 如何在页面底部加载css和js

妖精的绣舞 提交于 2019-12-07 12:21:44
作者:白狼 出处: http://www.manks.top/article/ yii2_load_js_css_in_end 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 正所谓命由己造,相由心生,那么我们的问题又是怎么抛出来的喃? 这个问题也算是个比较久远但是经常会有人要问到的问题。究其原因, 一来实际开发中不可避免,二来也就是刚接触yii的小伙伴喜欢揪着不放。那 为啥了解过这个问题的人就不纠结了喃?外星人:楼主你si不si撒,人家都了解怎么做了还纠结这个问题干嘛。 那行,关乎所以的人看看就行。 一般来说,网页内部的js文件或代码,都是放置在网页底部</body>的前面,这是因为网页自上而下加载,用户在访问我们页面的时候尽量不要因为加载js展现过长时间的空白页面,停留时间过长就白白流失了用户量。 yii2中是集成了jQuery的,而且jQuery文件是加载在页面底部的,因此,如果我们的js代码段不在页面底部加载,就很大可能会发生$未定义的友好提示。 我这废话一大堆得毛病确实需要去挂个号看看了... 先来看看js代码段怎么处理 <?php $this->registerJs(' $(function () { //为所欲为的写你想要写的js代码吧 $...... }); ', \yii\web\View:

How to create user session manage system in Yii2 with DbSession [closed]

冷暖自知 提交于 2019-12-07 11:03:37
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Today when I want to create user profile page for my website and want to create system users can manage his active sessions in this system need View active sessions Browsers and platform See what is current session remove unwanted active sessions How we can do this? 回答1: I Find

Yii2 Scroll Pager with overflow scroll

橙三吉。 提交于 2019-12-07 11:02:35
问题 i am using Yii2 with a scroll pager extension: http://kop.github.io/yii2-scroll-pager/ However, when you set the scroll for a div, instead of the whole screen, ajax is not loading any additional items when you scroll down. Here's my code: echo ListView::widget([ 'dataProvider' => $newsDataProvider, 'itemOptions' => ['class' => 'item'], 'itemView' => '_news_item_view', 'pager' => [ 'class' => \kop\y2sp\ScrollPager::className(), 'negativeMargin' => '200', 'triggerText' => 'Load More news',

Validation rules on behavior-created attributes

给你一囗甜甜゛ 提交于 2019-12-07 10:47:31
问题 I have a model with two values that has to be unique together. Yii2 has a validation rule for this: [['object_id', 'created_by'], 'unique', 'targetAttribute' => ['object_id', 'created_by']] The created_by attribute is generated with blameable behavior: public function behaviors() { return [ 'blameable' => [ 'class' => BlameableBehavior::className(), 'createdByAttribute' => 'created_by', 'updatedByAttribute' => 'updated_by', ], ]; } The validating is done before the behavior input is stored in

Yii 2.0 How to extend Core Classes

流过昼夜 提交于 2019-12-07 09:00:49
问题 I want to extend the class yii\web\Response . So I created a new class Response in the folder components and I try to overwrite the send method. namespace app\components; use Yii; class Response extends \yii\web\Response{ public function init(){ parent::init(); } /** * Sends the response to the client. */ public function send() { ... Finally I tried to import my new Response-Class by importing it in the config. $config = [ 'id' => 'basic', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'