https://www.youtube.com/watch?v=XyHHMvRt6Cw
Tuesday, January 19, 2021
.htaccess for Yii 2 advanced
Setting .htaccess for Yii2 advanced in Windows using Open Server. On the server with the unix system a .htaccess will work too, is checked.

Step-by-step instruction
Step 1
At the root of the project (@app) add a .htaccess with the following content:
- <IfModule mod_rewrite.c>
- Options +FollowSymlinks
- RewriteEngine On
- </IfModule>
- <IfModule mod_rewrite.c>
- RewriteCond %{REQUEST_URI} ^/(admin)
- RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
- RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
- RewriteRule ^admin/js/(.*)$ backend/web/js/$1 [L]
- RewriteCond %{REQUEST_URI} !^/backend/web/(assets|js|css|js)/
- RewriteCond %{REQUEST_URI} ^/(admin)
- RewriteRule ^.*$ backend/web/index.php [L]
- RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
- RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
- RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
- RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
- RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
- RewriteRule ^(.*)$ frontend/web/$1 [L]
- RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
- RewriteCond %{REQUEST_URI} !index.php
- RewriteCond %{REQUEST_FILENAME} !-f [OR]
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule ^.*$ frontend/web/index.php
- </IfModule>
Where admin - path to the @backend/web.
Step 2
In the folder @frontend/web add the file .htaccess with the following content:
- RewriteEngine on
- # if a directory or a file exists, use it directly
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- # otherwise forward it to index.php
- RewriteRule . index.php
Step 3
In the file @frontend/config/main.php in item components of array add:
- 'request' => [
- 'baseUrl' => '',
- ],
- 'urlManager' => [
- 'enablePrettyUrl' => true,
- 'showScriptName' => false,
- 'rules' => [
- '' => 'site/index',
- '<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
- ],
- ],
Step 4
In the folder @backend/web add the file .htaccess with the following content:
- RewriteEngine on
- # if a directory or a file exists, use it directly
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- # otherwise forward it to index.phpp
- RewriteRule . index.php
Step 5
In the file @backend/config/main.php in item components of array add:
- 'request' => [
- 'baseUrl' => '/admin',
- ],
- 'urlManager' => [
- 'enablePrettyUrl' => true,
- 'showScriptName' => false,
- 'rules' => [
- '' => 'site/index',
- '<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
- ],
- ],
Well done)
Thursday, June 11, 2020
Laravel Input multi dimensional array
Hi, in my template I have:
@for($i = 0; $i < 4; $i++)
{{ dd(Input::old('custom_link.0.title')) }}
<div class="form-group">
<label for="link_title_{{ $i }}">Link Title {{ $i+1 }}</label>
<input type="text" class="form-control" id="link_title_{{ $i }}" name="custom_link[{{ $i }}][title]" value="{{ Input::old('custom_link.0.title') }}">
</div>
@endfor
put template
{{ Input::old('custom_link.' . $i . '.title')) }}
After vlidation on controller I return
return Redirect::route('community-create-step-4')
->withErrors($validator)
->withInput();
Wednesday, June 10, 2020
Validation rules that depends on what the request is using condition
You could use the request helper:
public function rules()
{
$baseRules = [
'email' => 'required|email',
'g-recaptcha-response' => 'required|recaptcha'
];
if(request()->get("valueFromPost") === '2') {
return $baseRules + [
'confirm_email' => 'required|email|same:email'
];
}
return $baseRules;
}
Or the shorter (but less readable) version:
public function rules()
{
return [
'email' => 'required|email',
'g-recaptcha-response' => 'required|recaptcha'
] + (request()->get("valueFromPost") === '2' ? [ 'confirm_email' => 'required|email|same:email' ] : []);
}
Thursday, February 7, 2019
Camel case model relationship is returned as snake case property
Put following code in to your model class
| /** | |
| * Indicates whether attributes are snake cased on arrays. | |
| * | |
| * @var | |
| */ | |
Sample code as follows,
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Carbon\Carbon;
class BaseModel extends Model {
/**
* Indicates whether attributes are snake cased on arrays.
*
* @var bool
*/
public static $snakeAttributes = false;
}
Monday, September 24, 2018
fatal: refusing to merge unrelated histories
In my case, error was just
fatal: refusing to merge unrelated histories on every especially first pull request after remotely adding a git repo.
Using
--allow-unrelated-histories flag worked with pull request in this way:git pull origin branchname --allow-unrelated-historiesTuesday, September 18, 2018
How to remove "api" Prefix from URL
For Laravel 5.5:wn vote
accepted
It's just prefix to differ your api routes from other routes. You can add something different from
apito here.
In
app\Providers\RouterServiceProvider change this function: /**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
Remove prefixe line:
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
Subscribe to:
Posts (Atom)