#1285: Allow configuration of prefix for route generation through options
-------------------------+--------------------------------------------------
Reporter: david | Owner: dominik
Type: enhancement | Status: new
Priority: normal | Milestone: 1.0.4
Component: routing | Version: 1.0.3
Severity: minor | Keywords:
Has_patch: 0 |
-------------------------+--------------------------------------------------
Right now, when you have a console app and want to generate a URL, you can
do
{{{
#!xml
<ae:configuration context="web">
<routing class="AgaviWebRouting">
<ae:parameter name="gen_options_presets">
<ae:parameter name="console">
<ae:parameter
name="scheme">http</ae:parameter>
<ae:parameter
name="authority">www.agavi.org</ae:parameter>
<ae:parameter
name="separator"><![CDATA[&]]></ae:parameter>
</ae:parameter>
</ae:parameter>
</routing>
</ae:configuration>
}}}
But if you then generate the URL like this:
{{{
#!php
<?php
AgaviContext::getInstance('web')->getRouting()->gen('products.product.view',
array('id' => $product->getId(), 'foo' => 'bar'), 'console');
?>
}}}
the result will look something like this, because the Web Routing is not
running in a Web server context and thus of course cannot determine path
prefixes etc:
{{{
http://www.agavi.orgconsole.php/en/products/123456?foo=bar
}}}
The standard workaround is to do:
{{{
#!php
<?php
$_SERVER['SCRIPT_NAME'] = '';
AgaviContext::getInstance('web')->getRouting()->gen('products.product.view',
array('id' => $product->getId(), 'foo' => 'bar'), 'console');
?>
}}}
But that sucks, of course.
All we really need to make it work as intended is a new {{{gen()}}} option
called "prefix" so we can override the prefix if needed.
And then we can just configure the prefix (typically, it'll be empty if
the app runs in the document root):
{{{
#!xml
<ae:configuration context="web">
<routing class="AgaviWebRouting">
<ae:parameter name="gen_options_presets">
<ae:parameter name="console">
<ae:parameter
name="scheme">http</ae:parameter>
<ae:parameter
name="authority">www.agavi.org</ae:parameter>
<ae:parameter
name="prefix"></ae:parameter>
<ae:parameter
name="separator"><![CDATA[&]]></ae:parameter>
</ae:parameter>
</ae:parameter>
</routing>
</ae:configuration>
}}}
Which will mean that if we generate the URL again, we will get the
intended results:
{{{
http://www.agavi.org/en/products/123456?foo=bar
}}}
That's just one use case, but I suppose there are several others as well.
--
Ticket URL: <http://trac.agavi.org/ticket/1285>
Agavi <http://www.agavi.org/>
An MVC Framework for PHP5
_______________________________________________
Agavi Tickets Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/tickets