Good morning, I have a question about YII 1.1.
I manage a big project built on YII 1.1. It’s a multi domain CMS. The CMS managed a one page site for each domain until now.
Now we have to extend it to a multi page CMS. I want to be able to render each page of the site using a route such as: domain.com/about_me, domain.com/contacts, domain.com/services and so on.
Can I do this without create a controller for each page?
I know about url routes but here the problem is more complex. I want that all the controllers/actions work as before, but only for specific dynamic pages (eg. /contacts /about_me etc) if it’s present the relative view I want to show the relative page. And I wish that these were dynamic, that is: if the view exists (contact.php) show it on /contact, else 404 error
Your problem is to resolve conflicting namespaces in URLs, which can’t be done technically, it requires planning.
Can you reserve a base URL for all the dynamic pages? Something that isn’t part of any existing URL. It could be anything, e.g. /page/ or /exec/obidos/. Or something short like /1/ or /-/.
If the dynamic page names must be directly under / then you have to do something about all your existing URLs. You could reserve them so they can’t be page names (this is a really messy option). Or you could move them to be under a new base URL.
Hi thefsb, I’m going to simplify the question. Suppose that a CMS user wants to create a new page of the site. The page informations (such as ID, title, slug) will be saved on DB. Suppose that the page is titled “My new page” and I want that the page will point to domain.com/my-new-page. As you see, I need to dinamically manage the url, based on the page name. How can I do this?
There are a variety of solutions. I might use a URL schema like
/page-name ==> a public page, handled by route `page/read`
/-/controller/action ==> all other app routes
The business logic for creating a new page forbids page names starting with - (minus sign) or containing / (slash). PageController::actionRead($pageName) looks up a page in the DB by its name and renders it. So I need two URL rules
one might have a pattern like <pageName:[^-][^/-]*> that matches with the route page/read
the other matches /-/controller/action to routes controller/action