yii2

yii2 captcha not change on page refresh

喜欢而已 提交于 2020-04-13 06:13:10
问题 I am using the default captcha implementation of the yii2 advanced framework. I have a problem: I want to change my captcha code every time I refresh a page but when I refresh the page my captcha code does not change. 回答1: The most correct solution will be to create your own CaptchaAction , that extends yii\captcha\CaptchaAction and override the run() method as follows: namespace app\actions; // Change to your own class CaptchaAction extends yii\captcha\CaptchaAction { public $autoRegenerate

Yii2: How to access parameters in template mail?

别说谁变了你拦得住时间么 提交于 2020-04-11 05:14:40
问题 I have the following code: Yii::$app->mailer->compose('layouts/html', [ 'name' => $this->name, 'email' => $this->email, 'subject' => $this->subject, 'message' => $this->body]) ->setTo($this->email) ->setFrom([$this->email]) ->setSubject($this->subject) ->send(); How can I access the name, email, subject and message in layout/html.php? 回答1: It's simple you can access name, email, subject and message with $ sign. $name, $email, $subject, $message 回答2: In your example, you need to replace name

YII2 gridview sort sum of values of two columns

跟風遠走 提交于 2020-03-18 10:23:41
问题 I successfully displayed the 3 columns in the gridview. the attr1, attr2, and the sum of the 2 attributes. attr1 and attr2 are from the database and the 3rd column is their sum. How do I make the sorting and filtering work? Here is the gridview. [ 'label' => 'Number of Enquiries', 'value' => function ($model) { return $model->countEnquire + $model->countPhone + $model->countTrial; }, 'enableSorting' => true, ] How add sorting for this column? 回答1: OK, I don't have your full source code to go

yii2增加验证码详细步骤

两盒软妹~` 提交于 2020-03-16 18:56:09
某厂面试归来,发现自己落伍了!>>> 作者:白狼 出处: http://www.manks.top/article/yii2_captcha 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 本来以为yii2框架验证码这块很全面,尝试百度google了一下,大多数教程写的零零散散不全面,想着自己写一份带有完整步骤的验证码教程。 我们假设site/login 表单登录需要增加验证码。 1、siteController控制器的actions方法增加captcha设置 public function actions() { return [ 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'maxLength' => 4, 'minLength' => 4 ], ]; } 上面我们简单设置了验证码的位数,有小伙伴好奇都有哪些配置项,这个你可以查看文件 vendor\yiisoft\yii2\captcha,包括验证码背景色,字体文件等设置都可以在这里找到。 2、siteController继续配置。 public function behaviors() { return [ 'access' => [ 'class' => AccessControl:

Image path issue in yii2

一个人想着一个人 提交于 2020-03-06 03:01:11
问题 I have frontend,backend and API's in my yii2 project.I have remove front/web from url.I follow following post for that. http://www.yiiframework.com/wiki/755/how-to-hide-frontend-web-in-url-addresses-on-apache/ But my entire images getting not found error in backend and frontend.I am facing problem to give path.I have tried following code In params-local.php Yii ::setAlias('@source', 'http://example.com'); In Frontend/index.php <body style="background-image:url(.<?Yii ::getAlias('@source') ?>.

left join with ActiveRecord (yii2)

二次信任 提交于 2020-03-06 02:37:08
问题 I tried to send SQL request with LEFT JOIN but it doesn't display data from table2 table. public static function top($limit) { return self::findBySql(" SELECT * FROM table 1 g1 LEFT JOIN table2 s1 ON (g1.id = s1.g_id AND s1.id = ( SELECT MAX(id) FROM table2 s2 WHERE s2.g_id = g1.id )) LIMIT :limit", [':limit' => $limit] )->all(); } 回答1: It seems you are adding this function to the model and self represents the model itself. Yii will not return results from another table and will be limited to

How to transform raw SQL into Yii2 like find query

此生再无相见时 提交于 2020-03-05 05:20:04
问题 I can't convert raw SQL query in to Yii2 like method. I'd like to implement grid view from my RAW sql with filtering and sorting. I'm using ActiveDataProvider with method in the ModelSearch as Yii default way. I did try to use Model::findBySql but it is not letting me filter or sort my results in the grid view. I don't want to useSQLDataProvider because I have relations in my queries. I see that changing Model::FindBySql($sql) to Model::find is letting me sort and filter but the results are

Yii2 Invalid Configuration, cookieValidationKey must be configured with a secret key error when accessing the API

穿精又带淫゛_ 提交于 2020-03-05 00:21:13
问题 I am encountering an error whenever I am trying to access my self written API. { "name": "Invalid Configuration", "message": "yii\web\Request::cookieValidationKey must be configured with a secret key.", "code": 0, "type": "yii\base\InvalidConfigException", "file": "F:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\web\Request.php", "line": 1669, "stack-trace": [ "#0 F:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\web\Request.php(1651): yii\web\Request->loadCookies()", "#1 F:\xampp\htdocs

Yii2 \kato\DropZone file rename issue

元气小坏坏 提交于 2020-03-04 17:45:26
问题 I have created a dropzone in yii2 to upload images to server my dropzone widget is <?=\kato\DropZone::widget([ 'options' => [ 'url'=>'index.php?r=site/upload', 'maxFilesize' => '2', 'addRemoveLinks'=>true, 'renameFile'=>"function (filename) { return new Date().getTime() + '_' + filename; }" // 'autoProcessQueue'=>false ], 'clientEvents' => [ 'complete' => "function(file){console.log(file)}", 'removedfile' => "function(file){alert(file.name + ' is removed')}" ], ]);?> I want a unique name for

Yii2 Exception: ApcCache requires PHP apc extension to be loaded

て烟熏妆下的殇ゞ 提交于 2020-03-03 12:15:53
问题 I receive the exception when configure the cache components in main configuration of advanced-template frontend, on my php.ini the extension rsults enabled, how I can fix this problem? frontend/config/main.php: 'cache' => [ 'class' => 'yii\caching\ApcCache', 'keyPrefix' => 'myapp', // a unique cache key prefix ], The phpinfo() about apcu: 回答1: Solved by updating the configuration as follow: 'cache' => [ 'class' => 'yii\caching\ApcCache', 'keyPrefix' => 'myapp', // a unique cache key prefix