yii2

Using the 2 amigos file uploader in yii2

走远了吗. 提交于 2019-12-08 04:25:59
问题 Am implementing the 2amigos file uploader it only displays the interface but does not show or upload any file I have tried this: <?= FileUploadUI::widget([ 'model' => $evidence, 'attribute' => 'path', 'url' => ['media/upload', 'id' => $evidence], 'gallery' => false, 'fieldOptions' => [ 'accept' => 'image/*' ], 'clientOptions' => [ 'maxFileSize' => 2000000 ], // ... 'clientEvents' => [ 'fileuploaddone' => 'function(e, data) { console.log(e); console.log(data); }', 'fileuploadfail' => 'function

Yii2 RBAC DbManager error Call to a member function getRole() on null

≡放荡痞女 提交于 2019-12-08 04:13:41
问题 I've set up the database etc by having implemented SQL code to set up the tables and the rbac/init script to fill out the roles / permissions. I have an assign() at user creation but I keep receiving this error on the getRole(): yii\base\ErrorException Call to a member function getRole() on null public function addUser() { if($this->validate()) { $user = new User(); $auth_key = Yii::$app->getSecurity()->generateRandomString(32); $this->password = Yii::$app->getSecurity()->generatePasswordHash

Yii2 - How can I remove unnecessary information from log file?

一个人想着一个人 提交于 2019-12-08 03:13:39
问题 I am trying to log messages in Yii2 which are then emailed to my specified email address. config file web.php contains: 'mail' => [ 'class' => 'yii\log\EmailTarget', 'categories' => ['mail'], 'logVars' => [], 'mailer' => 'mailer', 'message' => [ 'from' => ['user@example.com'], 'to' => ['user1@example.com'], 'subject' => 'Log message', ], ], I am logging message like this: Yii::info('Log message example','mail'); After successful execution, I am receiving mail like this: 2018-07-31 09:01:12

In Yii2 framework, better place to define common function which is accessible everywhere like controller, model, view

牧云@^-^@ 提交于 2019-12-08 02:59:38
Like i want to create function with name "dt()" function dt(){ return date('Y-m-d H:i:s'); } and want to access it like this:- echo dt(); //retrun current date and time format Which is better place in Yii2 framework to do that? You can use it this way: http://www.yiiframework.com/extension/yii2-helpers/ Create a folder /common/helpers/ , then create a helper class there and add your static methods. namespace common\helpers; class DateHelper { public static function dt(){ return date('Y-m-d H:i:s'); } } Usage use common\helpers\DateHelper; echo DateHelper::dt(); For yii2, First Make a folder

Can someone explain how Yii minimizing assets is supposed to work on Heroku?

风格不统一 提交于 2019-12-08 02:44:26
I just got through getting the minification to work ( How do I combine & minify JS and CSS for a Yii app on Heroku? ) locally. However, it creates the all-1bc649be34b1e6afc9b2419687cde016.js file under web/assets/ . Yii creates a .gitignore to ignore everything in that directory. None of the files will make it to Heroku. Even if I use heroku run yii asset assets.php config/assets-prod.php it will only create ephemeral files that are not accessible to the web dynos. (As suspected it does fail in production. The CSS is not there!) How does minification work with Heroku? What happens if I change

Creating dropdown list from related table yii

半世苍凉 提交于 2019-12-08 02:43:34
问题 I have two tables: product and product_type (related to the models resp. Product and Product_type): product : product_id, product_type_id, name, etc... product_type : product_type_id, name, desc, etc... Both are related with key "product_type_id". I have created the crud for both tables using gii crud generator. Now on Product form page I want to display the listing of all product_type name in dropdown field using Yii ActiveRecord. I have added this line in views/product/_form.php script: <

Yii2 - Make hyperlink to toggle between languages

和自甴很熟 提交于 2019-12-08 02:23:37
问题 Hello. In Yii1.1 i could make an action in siteController and then using: Yii::app()->controller->createUrl('actionname', array('language'=>'new language to toggle')); It was possible to me to create hiperlinks with CHTML in index file and when clicked those hiperlinks changed the entire tranlations of the website from Portuguese to other language and all way around. Now i'm beginning with Yii2 and controller does not have createUrl() anymore. Also the other methods dont work that way. I

how to search filter multipe relation table and groupping in yii2

柔情痞子 提交于 2019-12-07 21:40:10
问题 I have three tables like ridersPoint (id, nameRider, serie_id, point) and series (serie_id, nameSerie, location, date, season_id) and season (season_id, nameSeason, year) . Attribute serie_id in riderPoint table have relation with serie_id in series table, and Attribute season_id in series table have relation with season_id in season table. How to make search by season_id in riderPoint ? And how to groupping point when have data table in the same season ? Please help me.. 回答1: Search (filter

谈谈yii2-gii如何自定义模板

懵懂的女人 提交于 2019-12-07 20:43:32
作者:白狼 出处: http://www.manks.top/article/yii2_gii_custom_template 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 yii2中gii给我们实际的使用提供了很大的方便。 但是,实际开发中,相信gii生成的模板也给很多开发者带来了不变,为啥?因为都是都是用人家的模板主动性生成的,自然不满足千万家的需求了,自家的需求还是自家定制的好,毕竟官方也只是尽可能的给出一个模板案例。 关于gii的介绍以及怎么使用可参考 官方文档说明 ,如果有哪里不懂的,下方留言我们共同交流。 yii2官方只提供了一种模板,但是也给我们提供了自定义的机会,接下来我们看看如何抓住这个机会去做点什么。 gii生成器所用到的模板文件位于目录 vendor\yiisoft\yii2-gii\generators\crud\default,因为要自定义模板,我们现在把default目录拷贝一份,粘贴到任意目录,这里我们粘贴在根目录下的giitemplate\curd下面,然后按照下面进行配置 $config['modules']['gii'] = [ 'class' => 'yii\gii\Module', 'allowedIPs' => ['127.0.0.1', '::1'],

Yii2的ActiveRecord与ActiveQuery简单介绍

╄→尐↘猪︶ㄣ 提交于 2019-12-07 20:43:08
活动记录 活动记录为与数据库中某张表中的 某条记录 相关联的 对象 ,我们通过调用此对象的 CURD方法对记录进行操作,Yii2的活动记录其实很标准,AR 类为模型Model,对应数据表,AR 类的实例为活动记录,对应表中某条记录。 在 Yii2 中活动记录为 AR 的实例,对应数据表中的某条记录 。 AR 的实例本身作为一条数据表中的记录不应该承担对表级别的操作 ,所以 Yii2 将此任务赋予了 AR 及其子类(我们自己写model)。我们可以调用相关的 类方法(即静态方法)对表进行检索从而获取我们想要的活动记录,当然, 这些静态方法也可以被此模型的实例所使用 (静态方法的特性) ActiveRecord 的 ORM 操作标准: 1、通过 AR 类访问数据库,检索其所对应的数据表获得符合条件的活动记录 2、对活动记录进行CURD操作 Yii2 的 AR 是通过调用 AQ 对其所关联的表进行检索操作,以下 AR 方法会返回 AQ 对象 User::find() //生成与当前AR所关联的表的AQ对象 User::findBySql($sql) //根据语句生成相对应AQ对象 $sql = "select * from yii_user where id = 1" 当进行关联查询的时候则是通过已经确定的活动记录对关联表进行条件检索 //关联查询时生成AQ $user->hasOne