How to add username in url before controller/action in yii2 - url-rewriting

I'm working on a site and I need to customize site URL in such a manner that it will work like <username>/<controller>/<action> after login the user.
I have tried it with followings rules in Yii 2.0 configuration file:-
'rules' => [
'<username>/<controller:(site|comment)>/<id:\d+>/<action:(index|home|update|delete)>' => '<controller>/<action>',
],
But it shows me #404 error. Any Helps?

Related

Laravel 5.5 Route groups

I was having this in my website using Laravel 5.3 :
Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware'=>'auth'], function(){
Route::resource('posts', 'PostsController');
});
This lets me go to the admin panel using: mywebsite/public/admin/posts.
Now, when I migrated the site to Laravel5.5 I got this error Route[admin.posts.create] not defined when i attempt to open the link Create post which was working fine before.
I know that routing system has changed but I did not know how to have such links in new Laravel5.5. I tried url instead of route but I got the same error. I also checked the new documentation but I did not get exactly how to have the same link system.
Can anyone have a better explanation of this new routing system? (I have to migrate the site to 5.5).
Laravel names resource routes by default, you can check them by running php artisan route:list
If you want to override them for any reason you can pass in an array when you define the route and override each individual route name like so:
Route::resource('posts', 'PostsController', ['names' => [
'create' => 'admin.posts.build'
]]);

Laravel 5 ElFinder Class replace-this-with-your-middleware does not exist error while browse server

I have configured elfinder in Laravel 5 and also using CKEditor. Everything was fine till until I click on browse server button and then I got "Class replace-this-with-your-middleware does not exist" error.
I have searched the web but I did not find any suitable answer. What can I try next?
You should write your middleware name in elfinder configs.
for example:
'route' => [
'prefix' => 'elfinder',
'middleware' => 'auth'/*replace-this-with-your-middleware*/, //Set to null to disable middleware filter
],
image

API and "normal" URLs in one Yii2 application

I would like to have (use) in my Yii2 application:
a standard, SEO-like URLs, with .html at the end (thus 'suffix' => '.html') and
API request (basing on very simple code) without this suffix.
So, to make my application being able to serve both http://127.0.0.1/app/site/index.html-like URLs and http://127.0.0.1/uslabs/web/user/2-like API calls.
It this possible? If so, how should I configure urlManager component for this?
I went through "Quick Start" chapter in "RESTful Web Service" section, but it bring no help. They don't use suffixes in examples given there. I'm stuck with the choice of either one or other scheme.
Yii has a REST url router that you can use to associate with certain controllers, like this;
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'suffix' => 'html',
'rules' => [
['class' => 'yii\rest\UrlRule',
'controller' => 'api',
'suffix' => NULL],
],
]
See the documentation for more details
According to this Yii Forum post, what I'm trying to do is possible, but tricky and not encouraged.
API calls should be handled by a separate application. At the end of "Quick Start" part for API-like apps in Yii2 guide there's a suggestion:
While not required, it is recommended that you develop your RESTful APIs as a separate application, different from your Web front end and back end for easier maintenance.

o-auth login with wykop.pl

Now I wish to build a login function with Wykop.pl API.
Can anybody help me to setup the thing?
As of now, I don't even have clue how to fill the
'scope' => array()
not to mention which privileges I should enable when connecting my app to wykop.pl
'Wykop' => array(
'client_id' => '423423',
'client_secret' => '0XMRI423423BfDFG',
'redirect_url' => 'http://www.appname.pl/dashboard',
'scope' => array('login', 'klucz_polaczenia','profile'),
),
This is a SDK for the site https://github.com/p1c2u/wykop-sdk
Unfortunately, as for now I am unable to translate the code into sth useful to me.
For the purpose of o-auth login, should scope include 'login' and 'klucz_polaczenia' ?
After the function is done, it would be a good idea to add the example to
this project repository of examples:
https://github.com/Lusitanian/PHPoAuthLib/tree/master/examples
Edit:
Wykop is not using o-auth... so the package I was trying to use is of no value.
Any help appreciated.
Edit 2:
The clostest I got to my goal is using this repo:
https://github.com/matiit/wkop
I did this recently. I'm using following workflow:
Display the login form to the user, with redirect set to callback.
Check the signature of callback, if correct then proceed.
Check, if I can login on Wykop.pl with received token, if so, then proceed.
Check, if user exists in my database, if so, I login him, if not, I create and login him.
Whole process of connecting with Wykop.pl API is available here: http://www.wykop.pl/dla-programistow/dokumentacja/#info6_7_5

YiiBoilerplate Url Rewriting - php yii

When we configure YiiBoilerplate. we use its frontend by these url
http://localhost/YiiBoilerplate-master/frontend/www/index.php/site/
i want to change this url and access it like
http://localhost/YiiBoilerplate-master/site/index.
how it is possible by mod_rewrite?
Add a .htaccess file to your webserver root:
RewriteEngine on
RewriteRule ^/YiiBoilerplate-master/(.*) /YiiBoilerplate-master/frontend/www/index.php/$1
This gives you access to your app via a shorter URL, but the links within the app still stay in the longer form. To update the URLs within your app, update baseUrl in the urlManager component:
'components' =>
'urlManager' => array(
'baseUrl' => '/YiiBoilerplate-master',
'urlFormat' => 'path',
...
Note: I'd strongly recommend setting up a virtual host.

Resources