How to create an application where you can use URLs like Facebook?
- app.dev/username
- app.dev/username/pictures
- app.dev/username/info
- app.dev/username/posts/post_333
- app.dev/username/posts/post_333/share
The application has other controllers with different URL’s
- app.dev/events
- app.dev/site/contact
- app.dev/site/terms
When the controler does not exist, redirect to the profile controller
in application.ini
autoloaderNamespaces[] = "Plugins"
resources.frontController.plugins[] = "Plugins_Profiles"
in Bootstrapp.php
protected function _initProfiles()
{
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Plugins_Profiles());
}
in /library/Plugin/Profiles.php
class Plugins_Profiles extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
if (!$dispatcher->isDispatchable($request)) {
$url = $request->getControllerName();
$request->setModuleName('default');
$request->setControllerName('profiles');
$request->setActionName('url');
$request->setParam('url', $url);
/** Prevents infinite loop if you make a mistake in the new request **/
if ($dispatcher->isDispatchable($request)) {
$request->setDispatched(false);
}
}
}
}
But I can not send variables
Ex: app.dev/username/posts/post_333/share
Any idea how I should proceed?
PS. Sorry about the grammar, I am Brazilian and I speak Portuguese.
You should check out Zend_Controller_Router_Route to get a clean url. Here are some links to get started with clean-url and zend route.