yii2

Yii2 : Show image from Folder Common

六月ゝ 毕业季﹏ 提交于 2019-12-18 09:09:06
问题 I have a picture in folder common that i want to show in view, but it doesn't shown. My code is : <img src="<?= Yii::$app->request->baseUrl . '/common/web/img/ava.jpg' ?>" class=" img-responsive" > It's generated to be <img src="/simdsm/common/web/ava.jpg" class=" img-responsive"> but the image does not appear. How to fix it? 回答1: In case of using advanced application template, images should be placed in these web accessible folders - frontend/web or backend/web . Also usually I create alias

Yii2-dynamicforms and javascript

早过忘川 提交于 2019-12-18 07:16:48
问题 I have wbraganca dynamic forms working in Yii2, but I need to add a little function to multiply 2 fields and put value in a third, and do that in every new dynamic form (suppose field 1 is price, field 2 is amount and field 3 is total). With the code I have I'm able to do that but only on the first dynamic form. <?php $script = <<< JS $('#itemsfactura-{$i}-cantidad').change(function(){ var cantidad = $(this).val(); var precio = $('#itemsfactura-{$i}-precio').val(); $('#itemsfactura-{$i}-total

How can I call a console command in web application in Yii 2.0

烂漫一生 提交于 2019-12-18 06:26:45
问题 I have a console command to generate user report. I want to call the same from my web application. I am using Yii 2.0.0 beta version.I tried to follow answers given in this post How to call a console command in web application action in Yii? Since Yii 2.0 structure is very different from Yii 1.1 ,I get errors if I try to include command/userReportController.php .Can someone guide me on this? 回答1: You should use an extension like https://github.com/vova07/yii2-console-runner-extension 回答2: I

How can I call a console command in web application in Yii 2.0

梦想的初衷 提交于 2019-12-18 06:24:03
问题 I have a console command to generate user report. I want to call the same from my web application. I am using Yii 2.0.0 beta version.I tried to follow answers given in this post How to call a console command in web application action in Yii? Since Yii 2.0 structure is very different from Yii 1.1 ,I get errors if I try to include command/userReportController.php .Can someone guide me on this? 回答1: You should use an extension like https://github.com/vova07/yii2-console-runner-extension 回答2: I

Yii2 Related table filter and sort with Grid View

眉间皱痕 提交于 2019-12-18 05:23:18
问题 I had this questions part by part and solve it now so I want to share maybe someone will use it. I have 4 models: Users,Certificate, Products, Autority. The main will be Users, from users Id we see certificate, from certificate Id we si the product id, from product id we see the autority. I solve it in one way so maybe someone can tell me if it is good or there are some other ways to do it. This will be step by step description. :) 1)In models set links between tables (hasOne, hasMany) (this

Yii Framework 2.0 Uploading Files Error finfo_file(): failed to open stream: No such file or directory

隐身守侯 提交于 2019-12-18 04:35:13
问题 Following Yii Framework 2.0 documentation http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html I tried to upload image. The image could be uploaded successfully, but after uploading the image, I tried to insert the model into the database with the following code. $model->file->saveAs('uploads/' . $model->file->baseName . '.' . $model->file->extension); $model->save(); I got the following error: PHP Warning – yii\base\ErrorException finfo_file(/tmp/phpIGuwiT): failed to open stream

Yii2 Dynamic URL Routing Rules

元气小坏坏 提交于 2019-12-18 04:24:27
问题 I want to set Dynamic Routing for url in Cms pages in yii2. When i add Cms page i will add page alias aboutus,faq,management etc , these alias will saved in db . When i give URL rule static it will work ,[check code below] 'urlManager' => [ 'showScriptName' => false, 'enablePrettyUrl' => true, //'enableStrictParsing' => true, 'rules'=>array( 'aboutus'=>'cms/index/1', 'faq'=>'cms/index/2', 'termacondition'=>'cms/index/3', 'management'=>'cms/index/4', ), ], But i want add url rule in

How to upload files in root folder in yii2 advanced template?

混江龙づ霸主 提交于 2019-12-18 04:23:32
问题 I am unable to upload files in root folder. I uploaded files in root folder and access these files in frontend and backend application. 回答1: When using the advanced template you need to decide on a common place to store your files that can be accessed by both the frontend and backend application, additionally if you want the files to be publicly accessible via the web you need to insure this location is a public folder. I tend to use the frontend/web folder as my common upload location. When

Yii2 ActiveRecord cache

 ̄綄美尐妖づ 提交于 2019-12-18 04:22:40
问题 How to use ActiveRecotd cache for Yii 2? I did't find any examples in official docs. In Google I found 2 examples, first is: $db = self::getDb(); $object = $db->cache(function ($db) use($id) { return self::findOne($id); }); But it doesn't work for Model , I tested with updated framework. Other example is: $data = \Yii::$app->cache->get('some_var_' . $id); if ($data === false) { $data = self::findOne($id); \Yii::$app->cache->set('some_var_' . $id, $data, 60); } It's working fine, but it's not

How to handle yii2 migrations on hosts without console access?

旧街凉风 提交于 2019-12-18 02:48:16
问题 I've succesfully created and uploaded advanced template on my shared host. As next step, I must run the yii migrate . But I cannot because I've not the console access. What could you suggest to me? Please note that I cannot change the host, because it's not a decision of mine I cannot access the server using SSH I've already tried something like PHPShell, but I got permissione denied when trying to run yii migrate --interactive=0 I tried also this: added an actionMigrateUp to frontend