yii2-advanced-app

Yii2: Remove controller from URL

醉酒当歌 提交于 2019-12-13 14:16:59
问题 I am using the advanced template. I created all my actions on the SiteController, so all my urls are domain.com/site/something, and I need to remove the word "site" from the url so it will be domain.com/something. I tried the following rules based on this question 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'showScriptName' => false, 'enablePrettyUrl' => true, 'rules' => array( '/<action:\w+>/<id:\d+>' => 'site/<action>', '/<action:\w+>' => 'site/<action>', '/noticia/<slug>' => 'site

Filtering yii2 grid using a form with related model

自作多情 提交于 2019-12-13 10:27:44
问题 Am using a search model with a search form and i would like to filter a grid view based on the value entered in the form. The form field is of a related table Am actually searching tblpritems and filtering its grid on the column pr_solicitation_id by entering supplier_id as in the tblprsuppliers This is the model relationships In the tblpritems public function getPrSolicitation() { return $this->hasOne(Tblprsolicitations::className(), ['pr_solicitation_id' => 'pr_solicitation_id']); } In the

Sliding image using yii2

守給你的承諾、 提交于 2019-12-13 05:48:45
问题 I want to make image slideshow in yii2, but unfortunatelly the image can't change. AppAsset: class AppAsset extends AssetBundle { public $css = [ // 'css/site.css', 'css/animate.css', 'css/font-awesome.min.css', 'css/main.css', 'css/prettyPhoto.css', ]; public $js = [ 'js/main.js', 'js/html5shiv.js', 'js/jquery.isotope.min.js', 'js/jquery.prettyPhoto.js', 'js/main.js', 'js/respond.min.js', ]; public $depends = [ 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', 'yii\bootstrap

Yii2 .htaccess redirect to backend part

安稳与你 提交于 2019-12-13 03:50:54
问题 I have installed Yii2 advanced app and what i am trying to do now is to redirect this url htpp://site/admin to the backend ( admin ) side. What i tried so far is: AddDefaultCharset utf-8 Options +FollowSymLinks IndexIgnore */* RewriteEngine on # Make the backend accessible via url: http://site/admin RewriteRule ^admin$ $admin.php [L] # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php

Search in Related Model using GridView Filter Field

你说的曾经没有我的故事 提交于 2019-12-13 02:48:43
问题 Question: Let's Say i have two tables, Table1 Table2 -authorId -username As of now my sql query on search model looks like this, ->andFilterWhere(['"Table1"."authorId"' => $this->authorName]); It only helps to search and filter using the authorID. Expected Result I would like to search based on the authorname instead of authorId. I faced similar difficulty in reflecting data in view but i was able to fix it with following getter function in base model. public function getAuthorName() { return

YII2 Redirect to backend after user registration from frontend

十年热恋 提交于 2019-12-13 00:48:22
问题 After installation of advance template in yii2, I got a user registration from at the frontend but I want it to redirect to backend after registration. How can that be done??? public function actionSignup() { $model = new SignupForm(); if ($model->load(Yii::$app->request->post())) { if ($user = $model->signup()) { if (Yii::$app->getUser()->login($user)) { return $this->goHome(); // I WANT TO CHANGE THIS TO REDIRECT TO LOCALHOST/MYAPP/BACKEND/WEB } } } return $this->render('signup', [ 'model'

Yii2: How to send new variable from view to controller?

安稳与你 提交于 2019-12-12 21:35:10
问题 I have a table called persons with id and name fields. I have a create.php view that loads the model called Persons and now I want to add a checkbox called hasCar to show if a person has a car (so it is a boolean condition). Then I have the send button that send the $model array of the form to the controller so I need to add the hasCar variable to $model array. But the checkbox is not a column of the persons table so I got some errors because it is not part of the model. I added the checkbox

Yii2 custom paginaion for Union query

烈酒焚心 提交于 2019-12-12 20:17:08
问题 I want to implement custom pagination in Yii2. this is my code $connection = Yii::$app->getDb(); $name = $_GET['name']; $query = ' SELECT name FROM user WHERE name LIKE "%.'$name'.%"" UNION SELECT name FROM user2 WHERE name LIKE "%.'$name'.%"" UNION SELECT name FROM user3 WHERE name LIKE "%.'$name'.%"" UNION SELECT name FROM user4 WHERE name LIKE "%.'$name'.%"" '; $result = $connection->createCommand($query)->queryAll(); Please let me know how can i implement pagination in Yii2 回答1: Plz try

How to use findAll() in yii2?

孤街醉人 提交于 2019-12-12 17:16:54
问题 I want to know how can i get all data of user with array id for where condition In yii you could do something like this $students = Student::model()->findAll("id IN ({$_POST['studentIds']})"); or $userDtls = Student::model ()->findAllByAttributes ( array ( 'id' => explode ( ",", $_POST ['studentIds'] ) ) ); Now in yii2 CDbCriteria is not there, so which approach should i use to achieve same thing?? I have tried this but it only returns data for first id in the array $result = Users::findAll([

ActiveForm without model yii2

房东的猫 提交于 2019-12-12 12:20:48
问题 I want to create ActiveForm without model for just in case something. I did try with dynamicModel but i got some error : use yii\base\DynamicModel; $model = DynamicModel::validateData(compact('KOMENTAR'), [ [['KOMENTAR'], 'string', 'max' => 128], ]); This is the form i want to create <br> <?php $form = ActiveForm::begin([ 'method' => 'post', ]); ?> <?= $form->field($model, 'KOMENTAR')->textarea(['rows' => 6])->label(false) ?> <div class="form-group"> <?= Html::submitButton('POST', ['class' =>