Answer the question
In order to leave comments, you need to log in
How to properly organize the structure for the mobile version of the site in Yii2?
Hello dear community.
I admit that the title does not convey the essence of the issue very well.
I ran into a problem. I need, for an already working site, to develop a mobile version that will be located on the m.site.com subdomain, respectively, the main version on site.com. For a number of reasons, we cannot use adaptive layout.
The project is developed on yii2.
At the moment, I connected to the autoload.php of the main project and to yii2 also installed via composer.
I copied from the main site the controller with the main pages (errors (500, 404) and the main page) and of course the views / layout and views / site folder. The framework started, but errors fell:
1. Didn't find app/models/Contact.
Я создал файл Contact.php в папке models объявлил namespace через include подключил данную модель с основного сайта, забыв что они лежат в одной области имен я объявил новый класс и унаследовал от основного - ест-но конфликт имен, я удалил объявление класса, но оставил include. Модель заработала!
Конечно, наследование, является более правильным решением, нежели то как оно работает в текущем виде. И что бы реализовать "правильно", думаю необходимо, либо иметь разные namespace на разных версиях сайта, меня это устраивает, либо создать в другой области имен базовые модели например в app\base\models\Contact и в каждой из версий сайта наследоваться от него.
2. There are many more conflicts with the scope and paths, for example, in yii\web\Assets (If I'm not mistaken), it loads bower/jqury/dist from the vendor folder, but it looks for this folder in the m.site.com directory.
The question to the community, of course, is how to properly organize the architecture of the project and how to avoid all current and future pitfalls as "correctly" as possible?
As I believe, it is necessary to make sure that all available namespaces app\models, app\controllers, etc. are loaded from the main version, including the vendor folder.
But for the second site, you need to declare some kind of mobile\models and mobile\controllers, with all this, the views folders must be loaded to each of their own.
It seems to me that you need to look in the direction of composer (autoload.php), in which I don’t understand anything by the way (tell me what needs to be rewritten, added, etc. in this file, where to look at all?) and somehow indicate new nemspaces for yii, not nails because it has nailed the use of app\controllers to load controllers?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question