Note that there are some explanatory texts on larger screens.

plurals
  1. POSilex variable mount point?
    primarykey
    data
    text
    <p>I have a series of pages that currently look something like this as route definitions:</p> <pre><code>$app-&gt;get('/{region}/{instance}/events', 'MyApp\EventsController::index'); $app-&gt;post('/{region}/{instance}/events', 'MyApp\EventsController::add'); $app-&gt;get('/{region}/{instance}/event/{id}', 'MyApp\EventsController::edit'); $app-&gt;post('/{region}/{instance}/event/{id}', 'MyApp\EventsController::update'); </code></pre> <p>I then have an <code>EventsController</code> class that has to have <code>region</code> and <code>instance</code> as parameters to all four functions (<code>index</code>, <code>add</code>, <code>edit</code>, and <code>update</code>). I'm wondering if it's possible to clean that up, and possibly move the <code>region</code> and <code>instance</code> values into the global <code>$app</code> object.</p> <p>I'd love to be able to do</p> <pre><code>$app-&gt;mount('/{region}/{instance}/', new MyApp\EventsControllerProvider()); </code></pre> <p>And have the <code>EventsControllerProvider</code> validate the <code>region</code> and <code>instance</code> variables, and map the "event" routes on top of that path, but it seems that mount points can't contain variables (the <code>ControllerProviderInterface::connect()</code> method doesn't allow extra parameters).</p> <p>Is there a clean way to do this? I thought of this method, which seems counter to the other routing mechanisms:</p> <pre><code>$app-&gt;get('/{region}/{instance}/{action}' function($region, $instance, $action) use ($app) { if ($app['myapp.valid-region']($region) === false) return $app-&gt;abort(404); if ($app['myapp.valid-instance']($instance) === false) return $app-&gt;abort(404); switch ($action) { case 'events': $c = new MyApp\EventsController(); return $c-&gt;index(); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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