Hi Szymon,

Thanks so much for your detailed reply below. I have been experimenting with 
this but however have a complication and would really appreciate if you could 
help me out.

To start, I have a administrator section that is to be kept separate from the 
public site
http://123.231.21.214/zend-test/public/admin/products/
(this is just a test url that we are working on - assume that 
"http://123.231.21.214/zend-test/public/"; is the public domain)

That works fine now. But when I edit my bootstrap.php file to use the routing 
functionality you mentioned, 

i.e.
$route = new Zend_Controller_Router_Route(
     ':publicsitecode/:controller/:action/*',
     array(
    'publicsitecode' => 'uk'
     )
);
$router->addRoute('default', $route);

then my "admin" section does not work. Everything renders to the index view.

So, I tried to change this by adding the following code, to keep a separate 
route to my "admin" section so that the AdminController is included:


$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route(
     'admin/:action/*',
     array(
    'action' => 'index'
     )
);
$router->addRoute('default', $route);
$route = new Zend_Controller_Router_Route(
     ':publicsitecode/:controller/:action/*',
     array(
    'publicsitecode' => 'uk'
     )
);
$router->addRoute('default', $route);


The above code correctly includes my AdminController. However, the view 
rendered is not the Admin views we were using..instead, the index view 
http://123.231.21.214/zend-test/public/
is displayed .. basically, the index view is included (which currently simply 
prints some basic text), whereas ZF should use the Admin view instead.

I tried it a different way, by using a static route
$route = new Zend_Controller_Router_Route_Static(
    'admin',
    array('controller' => 'admin', 'action' => 'index')
);
$router->addRoute('default', $route);

or
$route = new Zend_Controller_Router_Route_Static(
    'admin',
    array('controller' => 'admin', 'action' => 'index')
);
$router->addRoute('admin', $route);


But neither of these solved my problem :(

Before I go too deep into the rerouting for my public website, do you know:

a) How I can solve the above problem? so that my "admin" url is treated 
separately and the controller/view are taken from ZF in the 'usual' way?

b) How I can mimic an htaccess file to pass unlimited parameters, for example:
www.mydomain.com/products/boots/polly/5/black/
and
www.mydomain.com/products/boots/polly/5/
and
www.mydomain.com/products/boots/polly/
and
www.mydomain.com/products/boots/

should all be working URLs that either go to a products controller or action (I 
don't mind doing what is needed via a controller or action, whatever is more 
'normal' in terms of ZF coding to generate the content for the products page 
depending on the paramters passed via url)

Likewise, in the CMS part of the site,
www.mydomain.com/pages/about_us/
and
www.mydomain.com/pages/terms_and_conditions/

where the variable after "pages" in the URL is a special parameter that 
identifies the page via the database.

You have said that using ZF's Zend_Controller_Router_Route will solve my 
problem for multiple languages 
(e.g.
www.mydomain.com/pages/about_us/  will by default go to the English page 
identified by 'about_us', but
www.mydomain.com/de/pages/about_us/ will load the German page identified by 
'about_us')

however I am not sure how to tell ZF to load the correct controller/view and 
give the correct parameters to that controller, just like an htaccess file 
does. Any suggestions or further reading you can recommend?

Many thanks!
Rishi



--- On Fri, 6/20/08, SWilk <[EMAIL PROTECTED]> wrote:

> From: SWilk <[EMAIL PROTECTED]>
> Subject: Re: [fw-general] Creating a multiple language website to use the 
> same php scripts
> To: "Rishi Daryanani" <[EMAIL PROTECTED]>
> Cc: [email protected]
> Date: Friday, June 20, 2008, 3:00 PM
> Hi,
> 
> Rishi Daryanani wrote:
> > Hi,
> > 
> [....]
> > Basically we are planning to set up the English site
> > under the main domain and language sites under a
> > directory structure like the above, so the following
> > would be valid:
> > 
> > http://www.mydomain.com/ads/cars/36/
> > {shows content in English and uses a certain
> > controller and view to do this}
> > 
> > http://www.mydomain.com/sg/ads/cars/36/
> > (must use the same controller and view, but the site
> > id will be different (stored in a session) and
> > therefore display everything in the other
> > language/country
> > 
> > 
> > My question - how can I do this in ZF? 
> 
> 
> You should read about Zend_Controller_Router:
> 
> http://framework.zend.com/manual/en/zend.controller.router.html
> 
> You do not need to change anything in your
> controllers/actions.
> Just create a custom route which will recognize
> language/site in the 
> URL and set it as a Request parameter.
> 
> Just the top of my head and *not* tested, your route could
> read like this:
> 
> $route = new Zend_Controller_Router_Route(
>      ':language/:controller/:action/*',
>      array(
>       'language' => 'en'
>      )
> );
> 
> ...and replace default route with your custom route:
> 
> $router->addRoute('default', $route);
> 
> Someone please correct me if it's incorrect.
> 
> Now you would have language parameter in each Request and
> you can 
> access it the same way you access 'cars' parameter
> from your example Url.
> 
> Then, if you still need this language setting in your
> session (if 
> Request parameter is not enough) you should write a
> preDispach plugin, 
> in which you could set the session variable you need. A
> predispatch 
> plugin would take care of setting this session variable, so
> you need 
> not to do it in each controller.
> 
> 
> Hope this helps,
> --
> Szymon Wilkolazki


      

Reply via email to