yii2

How to create dependent dropdown in yii2

与世无争的帅哥 提交于 2019-12-09 23:46:03
问题 I use this code on backend/views/_form.php <?php $CoursesCat = ArrayHelper::map(CoursesCat::find()->all(),'id', 'cat_name'); $CoursesSubcat = ArrayHelper::map(CoursesSubcat::find()->all(),'id', 'name'); $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'cat_id')->dropDownList($CoursesCat, ['prompt'=>'-Choose a Category-', 'onchange'=>' $.post( "'.urldecode(Yii::$app->urlManager->createUrl('coursedetail/lists&id=')).'"+$(this).val(), function( data ) { $( "select#subcat_id" )

Compiling custom Bootstrap css in yii2 from less

你。 提交于 2019-12-09 19:44:53
问题 I'm starting a new project in Yii2 and Composer (after a few projects with YII 1). I created a new "advanced project" with composer. Everything is okay but, I'm wondering what is the best way to customize the bootstrap theme? I think copying the whole bootstrap less to the backend and to the frontend and edit the two variables file and compile it isn't the right way. So: is it somehow possible to extend the less files downloaded by the composer and edit only the two variables file? 回答1:

Yii2 Html::dropDownList and Html::activeDropDownList trade-off

拜拜、爱过 提交于 2019-12-09 17:00:40
问题 In Yii2, using Html::activeDropDownList , I can submit data in a form like the following: <?= Html::activeDropDownList($model, 'category', ArrayHelper::map($categories, 'id', 'name'), [ 'multiple' => 'multiple', 'class' => 'multiselect', ]) ?> Is there a way to specify pre-selected categories in the above? I know it can be done using Html::dropDownLost like the following: <?= Html::dropDownList('category', [1, 3, 5], ArrayHelper::map($categories, 'id', 'name'), [ 'multiple' => 'multiple',

Yii2 - Getting unknown property: yii\console\Application::user

╄→гoц情女王★ 提交于 2019-12-09 16:43:25
问题 I am trying to run a console controller from the terminal, but i am getting this errors every time Error: Getting unknown property: yii\console\Application::user here is the controller class TestController extends \yii\console\Controller { public function actionIndex() { echo 'this is console action'; } } and this is the concole config return [ 'id' => 'app-console', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'console\controllers', 'modules' => [],

The point of Yii2 environments folder

北城余情 提交于 2019-12-09 15:10:03
问题 I am trying to work what the point of the environments folder is. Originally I had the idea that you could point the webserver to the different dev and prod folders in the environment folder but after reading up a bit I realise this is not the case. In Yii 1 you would solve this by just having multiple index.php 's i.e.: index.php index-local.php So the question is what benefit does this new environment structure actually give me over the old way? 回答1: I've found environments very useful in

What the idea behind environment folders in Yii2 and how to use it?

試著忘記壹切 提交于 2019-12-09 14:29:23
问题 I've read through Yii2 documentation several times. I also googled and I couldn't find anything useful yet. The problem is I do not understand the concept of the environment folders. Please let me explain: I can use branches in Git (for dev, staging and production) *-local.conf files are ignored by Git and they won't be pushed to staging or production in anyway Why I have to duplicate all my controllers, views and other files in environment/dev & environment/prod ? In what folders I actually

Using Yii1 and Yii2 in the same project

两盒软妹~` 提交于 2019-12-09 12:04:45
问题 I had a project in Yii1.x and now I am using Yii2 for the same projects Project hierarchy is something like this Project1(yii1)/all yii files + project2(yii2) project2(yii2)/frontend + /common + /backend Now I want to know if is it possible to use project2/common/models in project1/protected/controllers How can I achieve this task? Thank you 回答1: I wouldn't recommend doing it, instead it's better to completely rewrite old application in Yii2. But in case of partial migrating, please read this

Getting the controller action before behaviour code runs in Yii2

放肆的年华 提交于 2019-12-09 11:52:45
问题 I'm trying to execute some code inside a Yii2 controller as I need some code from the model to be accessible within the behaviors section so I can pass the model as a parameter and avoid running duplicate queries; however I also need to be able to find out what action is being called, but I am not having much luck. I have tried using beforeAction but it seems this gets run AFTER the behaviours code runs, so that doesn't help me. I then tried using init , but it seems the action isn't

Need help to install yii2 application advanced template

混江龙づ霸主 提交于 2019-12-09 11:52:35
问题 I'm new to Yii2, now I'm trying to install yii2 application advanced template. I did follow these steps: 1 - Download yii2-app-advanced zip file from https://github.com/yiisoft/yii2-app-advanced 2 - Follow GETTING STARTED guide: + I'm using Uniform Zero Server (installed in F disk with the path "F:\Server\UniServerZ\www") ok. + I creted new folder with name "yii2" in the "www" directory ("F:\Server\UniServerZ\www\yii2") + I extracted zip file yii2-app-advanced into "yii2" folder (Every source

Yii 2.0 CSRF validation for AJAX request

妖精的绣舞 提交于 2019-12-09 10:10:44
问题 I have an ajax function that triggers an entry deletion from my database. I need to do CSRF validation for the same. How can I do that? I am sending the CSRF cookie along with my post request, but Yii 2.0 is not validating it and any input that is passed through ajax is reaching the server. How do I do CSRF validation for ajax requests. Whether we need to manually set cookie and check? 回答1: You don't need to manually set cookie. If you are using jQuery CSRF token will be sent automatically.