Goodnight. I am puzzled and can’t understand how I can implement multilingualism and switching between the admin panel and the regular version of the site.
I started writing my router, because I still don’t know how to find a common language with frameworks, I just can’t figure it out.
I really hope that there will be a person who will help me implement my version of routing. And so, I will describe the problem and the task:
I create a site. It is required to make multilingual (3 languages) and admin panel. Links should be of this type:
Regular version
http://web-site.com/http://web-site.com/catalog/auto/http://web-site.com/catalog/auto/product/product-url/http://web-site.com/
http://web-site.com/ru/http://web-site.com/ru/catalog/http://web-site.com/ru/catalog/auto/http://web-site.com/ru/catalog/auto/product/product-url/
If you add /admin/ in the address bar, then the redirect should work and connect the directory with the admin panel files.
http://web-site.com/admin/http://web-site.com/admin/products/auto/
The .htaccess file contains the following:
RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !^favicon\.ico RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?$1 [L,QSA] When I open the site, I want, say, the default Russian language, that is, a link like http://web-site.com/ is Russian, if the user chooses another language, then all links that are on the site are automatically formatted into specified locale, that is:http://web-site.com/catalog/ formatted in http://web-site.com/en/catalog/ . I have no idea how to convert all the links for the desired locale using php.
Then my router:
class Router { public $URI = []; public $TEMPLATE; public $MODULE = []; public $LOCALE; function __construct() { self::parseQueryString(); } function parseQueryString() { /** * Метод который парсит строку запроса, и возвращает массив $URI **/ $parsedString = parse_url($_SERVER['QUERY_STRING'], PHP_URL_PATH); $parsedString = explode('/', $parsedString); $this->URI = $parsedString; return $this->URI; } function setTemplate() { /** * Этот метод должен запустить проверку на существование шаблона * если таков есть, то возвращает название шаблона, если нет * то название шаблона ошибки **/ $template = $this->TEMPLATE; if (!$this->checkTemplate($template, $module)) $template = 'error'; return $template; } function checkTemplate($template, $module) { /** * Этот метод проверяет наличие файла (шаблона) * Возвращает TRUE | FALSE **/ $checkPath = $_SERVER['DOCUMENT_ROOT'] . '/application/views/' . $module . '/'; $checked = false; if (file_exists($checkPath . $template . '.php')) $checked = true; return $checked; } static function redirect($path = NULL) { /** * Статический метод обычной перезагрузки. * Использую после отправки формы методом пост, * либо когда это нужно **/ if (!$path) { $redirect = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_SERVER['REQUEST_URI']; header("Location: $redirect"); } else header("Location: /$path"); exit; } } It is not finished yet, for this reason I came to you. I hope someone will help finish or explain how to do it.
First of all, the router must accept and parse the address bar. I did this.
But now I need to define and format links automatically under the desired locale. For example, the user comes to the site:http://web-site.com/ gets to the main page with the Russian language. Then go to the product catalog http://web-site.com/catalog/ and switch to English, I need to redirect the user to http://web-site.com/en/catalog/ and in the router accept this /en/ and pass it to the $LOCALE variable, which I can then use to display the necessary information in the correct locale.
If in the address bar the user enters http://web-site.com/admin/ then he should be transferred to the authorization page of the admin panel. But I do not quite understand how to do this.
I have the following folder structure:
web-siteapplicationconfigsconfig.php
controllercontroller.php
core[dir]Router.phpDatabase.php
models[dir]CatalogModel.phpNewsModel.php- etc...
viewsweb_site[ types of site pages for a regular user ]control_panel[ types of admin panel pages ]
loader.php
cssimgjsuploadsindex.php
File loader.php all the necessary files at the very beginning.
Then I launch my router in the controller.php file.
Unfortunately, I don’t know where to go or what to do next. If you need more information, I will provide everything you need.