I have a route like this:
resources.router.routes.home.route = /:state/:city
resources.router.routes.home.defaults.module = default
resources.router.routes.home.defaults.controller = index
resources.router.routes.home.defaults.action = index
resources.router.routes.home.defaults.state = ''
resources.router.routes.home.defaults.city = ''
And most of the links from my site need these two parameters (state and city), like
www.mysite.com/sp/sao-paulo/establishments
www.mysite.com/sp/sao-paulo/establishment-name
www.mysite.com/sp/sao-paulo/establishments-category
What I need is to check if this two parameters are already set when the user accesses my website. If not, I'll redirect him to a specific page when he'll choose a city.
I believe the best way to achieve this is by creating a plugin, which I've already started.
class App_Controller_Plugin_CheckCity extends Zend_Controller_Plugin_Abstract {
protected $_session;
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$this->_session = new Zend_Session_Namespace('locationInformation');
if (!isset($this->_session->state) || !isset($this->_session->city)) {
// ...
} else {
// ...
}
}
}
The problem is I don't know exactly how to do it, and if this is really the best way.
Is this the correct path? If not, what can I do to solve my problem? If yes, what else this plugin needs?
I hope I made myself clear. I appreciate any help.
Thank you.