yii2

How we can save a image in a folder yii2 framework?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 17:16:51
问题 When i am uploading a image it is saved in default folder that is /web. I want to save my images in user defined folder. 回答1: If its a user defined folder, chances are pretty good you will have to create the directory on the fly, which the UploadedFile method does not do. For Yii2 I would use the createDirectory() method in the "yii\helpers\BaseFileHelper" class. ex: use yii\web\UploadedFile; use yii\helpers\BaseFileHelper; $model->uploaded_file = UploadedFile::getInstance($model, 'uploaded

Receiving HTTP data in Yii2 action from an Unknown URL

早过忘川 提交于 2019-12-11 17:14:47
问题 I have been trying to receive data send to my Yii2 action for a while now but to no success. I have tried lots of different algorithms and ideas. I am working on receiving data sent to me by Orange API for base on clients payment status. from Instructions on their website, they say, once the status has been confirmed, ..... HTTP notification is posted to the notif_url( my notification URL which I provided to them say https://www.example2.org/notif ). They futher provide the format for the

DatePicker widget filter a datetime field

a 夏天 提交于 2019-12-11 17:09:57
问题 Friends, how do I get my DatePicker component below (in Yii2 Framewok), filter a field of type datetime ? Since in the component I can only specify the date format. _search.php file: <?php echo DatePicker::widget([ 'model' => $model, 'attribute' => 'start_date', 'attribute2' => 'end_date', 'language' => 'pt', 'type' => DatePicker::TYPE_RANGE, 'separator' => 'até', 'options' => [ 'placeholder' => '', ], 'pluginOptions' => [ 'autoclose'=>true, 'todayHighlight' => true, 'format' => 'yyyy-mm-dd',

How to realize Yii2 relation through string not array?

折月煮酒 提交于 2019-12-11 17:08:14
问题 I have a class named ChatMessage. There are 2 main columns in DB (from_user, to_user). I want to relate one of these 2 columns to User model id. How can I use a relation query that looks like this public function getChattedUser() { return $this->hasOne(User::className(), '(case when(chat_message.from_user={Yii::$app->user->id}) then chat_message.to_user else chat_message.from_user END)=user.id'); } 回答1: Short answer: this is not possible . ActiveRecord relations are more complicated than you

Using custom validators with ActiveForm in Yii2

爱⌒轻易说出口 提交于 2019-12-11 17:04:43
问题 I want to make custom validation function like built-in validation required . I have example code here: Model: use yii\base\Model; class TestForm extends Model { public $age; public function rules(){ return [ ['age', 'my_validation'] ]; } public function my_validation(){ //some code here } } View: <?php use yii\helpers\Html; use yii\widgets\ActiveForm; $this->title = 'test'; ?> <div style="margin-top: 30px;"> <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'age')->label("age")

Impossible to get PHP Yii waiting TTFB time under 2s (with profiling results)

故事扮演 提交于 2019-12-11 16:55:35
问题 I created Yii2 basic app https://www.yiiframework.com/doc/guide/2.0/en/start-installation but the index.php waiting time (TTFB) always is around 2s, no less, download time is around 43ms and all the other resources of the default app (CSS, JS) are donwloaded withing 10ms (all as observed from Google developer tools), that is fine. I am running everything on my development machine Windows 10 4GHz, 16GB RAM, low resrouce consumption. I am adding the xDebug profiling results of index.php call:

How i can connect to Oracle database with Yii2?

半腔热情 提交于 2019-12-11 16:49:30
问题 We have a school work, and we make a website with yii2 framework. What is the problem? We cant use migration, what is the best way; we must to use an oracle database. We made it, tables, etc, but we dont know, how to connect this oracle ,,server,, with yii2. 回答1: You should go through the docs for Yii2. You have to add the configuration in the common/config/main.php or config/db.php , depending upon the version of Yii2 (Advanced or Basic), and under the components you have to add the database

yii2 form input ajax validation will not perfom

北城以北 提交于 2019-12-11 16:32:58
问题 im trying to active ajax validation in my form according the docs i added( 'enableAjaxValidation' => true and validationUrl )with its action can anyone tell me why validation will not perform on my form ? i dont have any error in console thankyou this is my controller public function actionCreate() { $model = new Developers(); return $this->render('_form', [ 'model' => $model ]); } public function actionValidation(){ $model = new Developers(); if(Yii::$app->request->isAjax && $model->load(Yii

yii2 user CRUD create or update with password

跟風遠走 提交于 2019-12-11 16:15:29
问题 I have a User model that stores the users in the database. With GII create a CRUD to be able to register and update users. The problem is with the password. How could I do for when I create a user to load a password and when I update it if I want to be able to update it? My table: CREATE TABLE user ( id int(11) NOT NULL, username varchar(250) NOT NULL, auth_key varchar(32) NOT NULL, password_hash varchar(255) NOT NULL, password_reset_token varchar(255) NOT NULL, email varchar(255) NOT NULL,

dynamic authTimeout: not overriding previous authTimeout value in Yii2

烂漫一生 提交于 2019-12-11 15:50:26
问题 I was looking to make dynamic authTimeout for users. So that user can set their timeout frequency. I came across Yii2 - How to set dynamic authTimeout in User Identity? And, then I changed web.php configuration 'user' => [ 'identityClass' => 'app\models\Users', 'loginUrl' => ['login'], 'authTimeout' => $params['LOGIN_TIMEOUT_DURATION'], //default 3600 'returnUrlParam' => 'return_url' ], to 'user' => [ 'class' => app\models\WebUser::class, 'identityClass' => 'app\models\Users', 'loginUrl' => [