Новости | FAQ | Авторы | Документация | В действии | Библиотека |
Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
Sumo 20.06.2014 16:34
Мы с вами говорим о некотором абстрактном алгоритме фронт-контролера, которого в природе не бывает. Все зависит от того как устроено ваше приложение, как оно разбито на модули, какая структура урлов и т.д. и т.п. Исходя из этого решите каким образом разбивать uri на части и как по нему искать нужный модуль и обработчик.$_routeRequirements[ $.articleID[\d+] ] ^router.assign[article/:articleID/edit;article/edit;$.requirements[$_routeRequirements]] ^router.assign[article/:articleID/publish;article/publish;$.requirements[$_routeRequirements]] ^router.assign[article/:articleID/showcomments;article/showcomments;$.requirements[$_routeRequirements]] ^router.assign[article/:articleID/hidecomments;article/hidecomments;$.requirements[$_routeRequirements]] ^router.assign[article/:{slug}-:articleID;article;$.requirements[$_routeRequirements]] ^router.assign[article/:articleID;article;$.requirements[$_routeRequirements]] ^router.assign[tags/:slug/rss;rss;$.name[tag-rss] $.strict(true) $.requirements[$_routeRequirements]] ^router.assign[tags/:slug;/;$.name[tag] $.strict(true) $.requirements[$_routeRequirements]]Для более навороченных приложений этот список становится еще больше:
$_routeRequirements[ $.clientID[\d+] $.personID[\d+] $.organizationID[\d+] $.calcID[\d+] $.pubID[\d+] $.specID[\d+] $.commentID[\d+] $.accountID[\d+] $.date[\d{4}-\d{1,2}] $.entityID[\d+] ] ^router.assign[new/bycalc/:calcID;new/bycalc][$.requirements[$_routeRequirements]] # Клиенты ^router.assign[:clientID;client][$.requirements[$_routeRequirements]] ^router.assign[:clientID/edit;client/edit][$.requirements[$_routeRequirements]] ^router.assign[:clientID/setstart;client/setstar][$.requirements[$_routeRequirements]] ^router.assign[:clientID/unsetstar;client/unsetstar][$.requirements[$_routeRequirements]] ^router.assign[:clientID/undo;client/undo][$.requirements[$_routeRequirements]] ^router.assign[:clientID/delete;client/delete][$.requirements[$_routeRequirements]] # Сотрудники ^router.assign[:clientID/persons/new;persons/new][$.requirements[$_routeRequirements]] ^router.assign[:clientID/persons/:personID;persons/edit][$.requirements[$_routeRequirements]] ^router.assign[:clientID/persons/:personID/delete;persons/delete][$.requirements[$_routeRequirements]] ^router.assign[:clientID/persons/:personID/restore;persons/restore][$.requirements[$_routeRequirements]] # Организации ^router.assign[:clientID/organizations/new;organizations/new][$.requirements[$_routeRequirements]] ^router.assign[:clientID/organizations/:organizationID;organizations/edit][$.requirements[$_routeRequirements]] ^router.assign[:clientID/organizations/:organizationID/delete;organizations/delete][$.requirements[$_routeRequirements]] ^router.assign[:clientID/organizations/:organizationID/restore;organizations/restore][$.requirements[$_routeRequirements]] # Издания ^router.assign[:clientID/pubs/:pubID;pubs][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/new;pubs/new][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/new/bycalc/:calcID;pubs/new/bycalc][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/:pubID/edit;pubs/edit][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/:pubID/delete;pubs/delete][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/:pubID/restore;pubs/restore][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/:pubID/specs/new;pubs/specs/new][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/:pubID/specs/:specID/edit;pubs/specs/edit][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/:pubID/specs/:specID/delete;pubs/specs/delete][$.requirements[$_routeRequirements]] ^router.assign[:clientID/pubs/:pubID/specs/:specID/restore;pubs/specs/restore][$.requirements[$_routeRequirements]] # Заказы ^router.assign[:clientID/pubs/:pubID/orders;orders][$.requirements[$_routeRequirements]] ^router.assign[:clientID/orders;orders][$.requirements[$_routeRequirements]] # Калькуляции ^router.assign[:clientID/calcs;calcs;$.name[client-allcalcs] $.requirements[$_routeRequirements]] ^router.assign[:clientID/calcs/:calcID;calcs/calc;$.strict(true) $.name[client-calc] $.requirements[$_routeRequirements]] ^router.assign[calcs/:calcID;calcs/calc;$.strict(true) $.name[client-calc] $.requirements[$_routeRequirements]] ^router.assign[:clientID/calcs/new;calcs/new;$.name[client-new-calc] $.requirements[$_routeRequirements]] # Контакты ^router.assign[comments/:date;comments; $.requirements[$_routeRequirements]] ^router.assign[:clientID/comments;comments/client; $.requirements[$_routeRequirements]] ^router.assign[:clientID/comments/:commentID/edit;comments/edit; $.requirements[$_routeRequirements]] ^router.assign[:clientID/comments/:commentID/remark;comments/remark; $.requirements[$_routeRequirements]] ^router.assign[comments/:commentID/edit;comments/edit; $.requirements[$_routeRequirements]] ^router.assign[comments/:commentID/remark;comments/remark; $.requirements[$_routeRequirements]] ^router.assign[:clientID/comments/:entityType/:entityID/new;comments/new;$.requirements[$_routeRequirements]] ^router.assign[comments/:entityType/:entityID/new;comments/new;$.requirements[$_routeRequirements]] ^router.assign[:clientID/comments/new;comments/new; $.requirements[$_routeRequirements]] # Лицевой счет ^router.assign[:clientID/accounts;accounts; $.requirements[$_routeRequirements]] ^router.assign[:clientID/accounts/new;accounts/new; $.requirements[$_routeRequirements]] ^router.assign[:clientID/accounts/:accountID/edit;accounts/edit; $.requirements[$_routeRequirements]] ^router.assign[:clientID/accounts/:accountID/delete;accounts/delete; $.requirements[$_routeRequirements]]У меня это все загнано на уровень фреймворка, потому что делать такие вещи для каждого проекта вручную смысла нет.