Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to define your web application URLs
    text
    copied!<p>I've always found that defining URLs for other "pages" in a Web Application seems either clumbsy and fragile or bloated.</p> <p>E.g. you have an application that manages customers, sales, prospects and thus has the following "pages".</p> <ul> <li>customerlist</li> <li>viewcustomer</li> <li>editcustomer</li> <li>addcustomer</li> <li>viewcontact</li> <li>editcontact</li> <li>addcontact</li> <li>prospect (x3? x4?)</li> <li>sales (x?)</li> <li>product (x?)</li> <li>request (x?)</li> <li>forecast (x?)</li> <li>etc. ...</li> </ul> <p>As an application grows, the number of pages grows to a list of 100+ URLs in no time.</p> <p>Logic says that just copy/pasting these URLs in where needed on a page is ugly and a pain to maintain, but loading up 100+ key/values seems redundant if you only need 2 or 3 of them on "this" page.</p> <p>Technically this is a language-agnostic (ASP,JSP,PHP,RoR,Python,etc.) question but I intend to implement in PHP (in an MVC setup). However if ASP.Net or Rails has a "really cool" way of doing this I'm all ears.</p> <p><strong>Update:</strong></p> <p>I'm mid-way through converting a non-MVC PHP app to use an MVC structure. Previously I had a big set of key'd links that were the base URL for a page, e.g.:</p> <pre><code>$URLs['CUSTOMER_ORDER_CONTACTS'] = '/customerordercontacts.php'; $URLs['CUSTOMER_PRODUCTS_EDIT'] = '/editcustomerproducts.php'; //etc. </code></pre> <p>Since I might be linking to the "Customer Products Edit" screen from anywhere, each page loaded this list, so that if/when the URL changed to another page... changing the item in the list would update all links.</p> <p>However as I read the answers here I think I might have answered my own question by accident. What @Blixt wrote is pretty much the structure I have/plan to follow... at which point the URL is really <strong><em>structured</em></strong> in such a way that <em>I don't need to have this list at all</em>:</p> <p>Example: If I am rendering a customer... and want to provide a link to each contact</p> <pre><code>//pseudo code $contacts = $customer.getContacts(); //previous rendering list of links foreach($contacts as $key =&gt; $value){ echo('&lt;a href="'.$URLs['CUSTOMER_CONTACT_VIEW'].'?customer='.$custID.'&amp;contact='.$key.'"&gt;'.$value.'&lt;/a&gt;'); } //new rendering list of links foreach($contacts as $key =&gt; $value){ echo('&lt;a href="/customer/'.$custID.'/contact/'.$key.'"&gt;'.$value.'&lt;/a&gt;'); } </code></pre>
 

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