Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I introduce a regex action to match the first element in a Catalyst URI?
    primarykey
    data
    text
    <p><strong>Background:</strong></p> <p>I'm using a CRUD framework in Catalyst that auto-generates forms and lists for all tables in a given database. For example: /admin/list/person or /admin/add/person or /admin/edit/person/3 all dynamically generate pages or forms as appropriate for the table 'person'. (In other words, Admin.pm has actions edit, list, add, delete and so on that expect a table argument and possibly a row-identifying argument.)</p> <p><strong>Question:</strong></p> <p>In the particular application I'm building, the database will be used by multiple customers, so I want to introduce a URI scheme where the first element is the customer's identifier, followed by the administrative action/table etc:</p> <ul> <li>/cust1/admin/list/person</li> <li>/cust2/admin/add/person</li> <li>/cust2/admin/edit/person/3</li> </ul> <p>This is for "branding" purposes, and also to ensure that bookmarks or URLs passed from one user to another do the expected thing.</p> <p>But I'm having a lot of trouble getting this to work. I would prefer not to have to modify the subs in the existing framework, so I've been trying variations on the following:</p> <pre><code>sub customer : Regex('^(\w+)/(admin)$') { my ($self, $c, @args) = @_; #validation of captured arg snipped.. my $path = join('/', 'admin', @args); $c-&gt;request-&gt;path($path); $c-&gt;dispatcher-&gt;prepare_action($c); $c-&gt;forward($c-&gt;action, $c-&gt;req-&gt;args); } </code></pre> <p>But it just will not behave. I've used regex matching actions many times, but putting one in the very first 'barrel' of a URI seems unusually traumatic. Any suggestions gratefully received.</p>
    singulars
    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.
 

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