We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Sharding app by city

Good day! I have a question to your wonderful community: We must be in the application sharing by city: site.com/city1 site.com/city2 site.com/city3 etc. Each city "unique design" (logos, content) As implemented in the Phalcon without writing a controller for each city? Or is it, in this case it's the right decision?

Thank you, Phalcon!

You can set up a route so site.com/city1, site.com/city2, site.com/city3, etc all run the same controller & action. The route can be configured to set "city1", "city2","city3" as a variable you can access via the dispatcher. You can then update your interface accordingly.



1.4k
edited Nov '14

If all that's changing between the different URLs is a view of the data, I would route everything into the same controller/action as quasipickle mentioned. You can do with a route like:

$router->add( "/{city:[a-z]+}", array( "controller" => "city", "action" => "index" ) );

However, this will catch everything like site.com/not-a-city, which is likely bad. I would instead recommend you something instead like:

$router->add( "/city/{city:[a-z]+}", array( "controller" => "city", "action" => "index" ) );

This way you can still have other pages that don't conflict with city.

Note once you're in your index action, you can then render your template file using the getParam ... this will let you isolate city1 and city2 into separate templates without having to code new controllers or routes.