yii2

Yii2: differences between init() and bootstrap() and best place to add dynamical URLs on a module

做~自己de王妃 提交于 2019-12-11 01:07:34
问题 I dont understand exactly what is the difference between use init() and bootstrap() on a class. My case: I want to add dynamical urls from my module by using Yii::$app->urlManager->addRules(...) but NOT loading the module in order to improve the performance. So, I thought if bootstraping the module from the main configuration file like: 'bootstrap' => ['mymodule'] , the Module::bootstrap() function will be executed ONLY and exclusively. But actually always runs Module::init() function, and

How to sort by related table field when sending Yii2 REST GET request

两盒软妹~` 提交于 2019-12-11 00:35:35
问题 I want to expand this question. Basically I have users endpoint. But I am also returning data from the related profiles table. I am not expanding with profiles, I always want to return it. So I have fields method like this: public function fields() { $fields = parent::fields(); $fields[] = 'profile'; return $fields; } When I do GET request and demand sorting by profile.created_at field and user.status, it does not sort by profile.created_at. GET v1/users?sort=-profile.created_at,status Can

How to make two apps Yii1 and Yii2 use the same session?

青春壹個敷衍的年華 提交于 2019-12-11 00:30:18
问题 I want to make a dashboard panel web in my existing website. The existing app is using Yii1 can be accessible via, let's say, www.example.com . I want to make www.example.com/dashboard using new app using Yii2. I already made the apache configuration. But what's missing is the session. Users that logged in through Yii1 app will not be recognized in the dashboard. How to make Yii1 and Yii2 use the same session data, i.e. user that logged in at Yii1 will be recognized in Yii2 vice versa? UPDATE

Yii2 Url Html format

偶尔善良 提交于 2019-12-11 00:27:38
问题 Quick Question: i use following code in my View Script to generate a link <?=HTML::a("(".$player['player']->steam_id_32.")",['steam/','steamid'=>$player['player']->steam_id_32])?> This is going to return following link /web/steam/STEAM_0%3A0%3A96553432 how can i have it return /web/steam/STEAM_0:0:96553432 i tried some thing but could not figure it out thank you 回答1: This behavior is by design. You can't really change this behavior, but you could use a workaround. The code below first creates

Yii framework 2.0 add media print to css link

↘锁芯ラ 提交于 2019-12-11 00:23:59
问题 Working with Yii framework 2.0 I include a css file with the code below inside assets/AppAsset.php . public $css = [ 'css/style.css', ]; When I inspect element on the web browser I see the following code in the header tag: <link href="/locahost/mywebsite/css/style.css" rel="stylesheet"> I would like to add the print.css to the web page with media='print' . How could I add the attribute media='print' into the css link within Yii framework 2.0? 回答1: There is a cssOptions attribute for the

REST API error “CORS preflight channel did not succeed”

你。 提交于 2019-12-10 23:43:24
问题 I created a RESTapi to insert data into my databse, It's working perfectly on POSTMAN extension, but I'm getting an error on angularjs http post method. My Restapi code is created in yii2 framework. My code is below, public function actionNew() { $model = new Apieducation(); $user_id = $_REQUEST['user_id']; $education = $_REQUEST['education']; $passing_year = $_REQUEST['passing_year']; $institute = $_REQUEST['institute']; //$model->attributes=$params; $model->user_id = $user_id; $model-

Radio Button - Yii2-Basic-App

让人想犯罪 __ 提交于 2019-12-10 23:28:53
问题 In radio button, value is coming. But, I want to display the name of that value. my user_types (table) id type status created_at 1 An Individual 1 2015 2 Firm 1 2015 UserController.php (controller) public function actionRegister() { $model = new Users(); . . $modelUserType=UserType::find()->select(['id', 'type'])->where(['status' => 1]) ->indexBy("id")->column(); return $this->render('register', [ 'model' => $model, 'modelUserType'=>$modelUserType, 'module' => $this->module, ]); } register

Yii2 share session between 2 apps

一个人想着一个人 提交于 2019-12-10 23:28:10
问题 Currently, my application have the following structure: frontend backend (user authenticated) client (user authenticated) What I'm trying to do is to pass a flash message from the client to the frontend . In the client app I simple set the flash: Yii::$app->session->setFlash('successMessage', 'My success message!'); And in the frontend: Yii::$app->session->getFlash('successMessage'); But the above obviously is not working. I've already tried to set equal session id in the config/main.php of

Error in uploading files in yii2 move_upload function

ぐ巨炮叔叔 提交于 2019-12-10 23:19:01
问题 Am doing multiple file upload in the controller but the file doesn't get uploaded controller code: for the upload $images = $_FILES['evidence']; $success = null; $paths= ['uploads']; // get file names $filenames = $images['name']; // loop and process files for($i=0; $i < count($filenames); $i++){ //$ext = explode('.', basename($filenames[$i])); $target = "uploads/cases/evidence".DIRECTORY_SEPARATOR . md5(uniqid()); //. "." . array_pop($ext); if(move_uploaded_file($images['name'], $target)) {

Yii2: Finding file and getting path in a directory tree

六月ゝ 毕业季﹏ 提交于 2019-12-10 22:04:45
问题 I'm trying to search for a single filename in a bunch of directories and returning its path. I thought FileHelper::findFiles() would be a helping hand but it seems it doesn't accept a filename to search for but just a particular root directory and then it returns an array of found filenames. Anyone who knows another Yii2 helper to accomplish this? 回答1: You should simply try: $files = yii\helpers\FileHelper::findFiles('/path', [ 'only' => ['filename.ext'], 'recursive' => true, ]); Read more