Bularni yaxshi bilsangiz kerak, bular basic va advanced;
Bularni farqlarini quyidagi rasm orqali bilib olishingiz mumkin .
Advanced template frontend va backend applicationlarga ajratilgan. Ko'pchiligimiz advanced templateni ishlatamiz. Odatda frontend - asosiy sayt uchun, backend - admin panel uchun ishlatamiz.
(Bularni yoniga xohlagancha qo'shib ketishimiz mumkin, misol uchun api va hakazo)
Endi shu yerda backend application ni admin uchun ishlatishni ko'rib chiqsak.
Web serverimizda yangi proyekt yaratib, unga yii2 advanced application templateni o'rnatamiz:
mysite.uz/
backend/
common/
console/
environments/
frontend/
vagrant/
vendor/
other files...
Endi apacheda virtual host qo'shib, uni sozlaymiz:
<VirtualHost *:80> ... ServerAlias www.mysite.uz DocumentRoot /var/www/mysite.uz ... </VirtualHost>
DocumentRoot ga /var/www/mysite.uz/frontend/web papkasini ko'rsatmaymizmysite.uz papkasini ichida .htaccess faylini qo'shamiz va ichiga quyidagilarni yozamiz:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(frontend/web)
RewriteRule ^assets/(.*)$ /frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
RewriteRule ^img/(.*)$ frontend/web/img/$1 [L]
RewriteRule (.*) /frontend/web/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /frontend/web/index.php
endi adminka qismiga o'tsak.
http://mysite.uz/admin deb chaqirganimizda adminkani ochib berishi kerak;
(aynan "admin" bo'lishi shart emas, o'zingiz hohlaganni yozishingiz mumkin, misol uchun "adminboy")
mysite.uz/ papkasini ichida "admin" degan papka qo'shamiz va backend/web/ papkasini ichidagi hamma fayl va papkalarni copy qilib "admin" papkasini ichiga paste qilamiz.
"index.php" faylini ochib undagi pathlarini to'g'irlab olamiz, yani config fayllarni yo'llarini to'g'ri ko'rsatish kerak:
<?php
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'prod');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../common/config/bootstrap.php');
require(__DIR__ . '/../backend/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../common/config/main.php'),
require(__DIR__ . '/../common/config/main-local.php'),
require(__DIR__ . '/../backend/config/main.php'),
require(__DIR__ . '/../backend/config/main-local.php'));
(new yii\web\Application($config))->run();
Keyingi qadamda "admin" papkasini ichida ham .htaccess faylini yaratamiz va ichiga quyidagilarni yozamiz:
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
endi http://mysite.uz/admin deb brovzeringizda yozsangiz admin panelga kiradi.
Maqola shoshilinch yozildi, xatolari bo'lsa sizlardan uzr so'rayman.
Savollaringiz bo'lsa dsq2190@gmail.com ga yozishingiz yoki telegramda @sardordushamov ga murojaat qilishingiz mumkin.
No comments:
Post a Comment