Note that there are some explanatory texts on larger screens.

plurals
  1. POAdvice on Refactoring Custom Routing Scenario (Lithium Framework)
    text
    copied!<p>A continuation from previous question: <a href="https://stackoverflow.com/questions/8717119/custom-lithium-routing-scenario">Custom lithium routing scenario</a></p> <p><strong><em>Note: This is specific to the <a href="http://lithify.me/" rel="nofollow noreferrer">Lithium Framework</a></em></strong></p> <p><strong>The Problem</strong></p> <p>I've inherited a URL scheme that doesn't really have any convention to differentiate between pages, items and categories. So, I've got a very generic router that passes to a catch-all controller.</p> <p>This catch-all controller (PagesController) uses the url as key to retrieve Page Type from a database. The PagesController then runs methods and chooses templates based on a Page Type. I store this information in Memcached indefinitely, so lookups are quite fast.</p> <p>However, as more page types come into play, I can see this controller becoming too bloated and inflexible. Ideally, I would like to break the different page types out into their own controllers.</p> <p><strong>The Solution?</strong></p> <p>Would it be possible to have a routing scenario that checks the database to determine the correct controller?</p> <p>My first thought is to subclass <code>lithium\net\http\Router</code> and use custom logic in <code>Router::connect()</code> and <code>Router::_parseController()</code>.</p> <p>It would be nice if could query the database in bootstrap\routes.php and create a new <code>lithium\net\http\Route</code> object based on the results. Then, simply pass this to <code>Router::connect()</code>. This seems like an awful hack.</p> <p>Either way, <code>Router::connect()</code> in it's design isn't meant to be <em>that</em> dynamic.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload