-- Jack Sleight <[EMAIL PROTECTED]> wrote
(on Thursday, 01 November 2007, 07:07 AM -0700):
> I'm trying to do something similar to this as well, but have a problem. I
> have this code:
>
> if (preg_match('/^\/(en|de)(.*?)$/', $uri, $matches)) {
> $request->setRequestUri($matches[2]);
> }
>
> Which works. /about, /en/about and /de/about all go to the right place. But
> the URLs created with the view URL helper don't contain the language code
> that was stripped from the request URL. How can I get it to leave this on if
> it exists?
First, in your regex above, I'd also store the matched language in the
registry so you can retrieve it later:
Zend_Registry::set('language', $matches[1]);
I'd create your own Url helper extending Zend_View_Helper_Url, and have
it prepend the string with the language:
class My_View_Helper_Url extends Zend_View_Helper_Url
{
public function url(array $urlOptions = array(), $name = null, $reset =
false)
{
$url = parent::url($urlOptions, $name, $reset);
if (Zend_Registry::isRegistered('language')) {
$url = '/' . Zend_Registry::get('language') . $url;
}
return $url;
}
}
Then, simply register the path to this helper in your bootstrap or a
plugin:
$view->addHelperPath('/path/to/My/View/Helper', 'My_View_Helper');
When you call on the 'url' helper later, it will find yours as it will
have been registered later, which means you won't need to change your
view scripts. :-)
> I tried playing with the setBaseUrl method, but whatever I set it to seemed
> to break it.
>
> Thanks.
>
>
> Matthew Weier O'Phinney-3 wrote:
> >
> >
> > You have two options. One is to create your own default route by
> > extending Zend_Controller_Router_Route_Module and modifying it to check
> > for a language segment in the first path position. The second is to
> > strip it off the request URI and pass the modified request URI to
> > the request object in your bootstrap:
> >
> > $uri = $_SERVER['REQUEST_URI'] ;
> > if (preg_match('#^/([a-z]{2})/#', $uri, $matches)) {
> > Zend_Registry::set('language', $matches[1]);
> > $request = new Zend_Controller_Request_Http();
> > $uri = substr($uri, 4);
> > $request->setRequestUri($uri);
> > $front->setRequest($request);
> > }
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Zend-Frmework-Language-ID-Prefixing-tf4686873s16154.html#a13529393
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/