Skip to content

Instantly share code, notes, and snippets.

@samdark
Created August 3, 2011 22:36
Show Gist options
  • Save samdark/1124018 to your computer and use it in GitHub Desktop.
Save samdark/1124018 to your computer and use it in GitHub Desktop.
Yii: Simple HMVC
<?php
/**
* Yii, simple HMVC
*/
class HmvcController extends Controller
{
public function actionIndex()
{
echo $this->execute('/hmvc/do/id/123');
}
/**
* Processes the request using another controller action and return output.
*
* @param string $route the route of the new controller action. This can be an action ID, or a complete route
* with module ID (optional in the current module), controller ID and action ID. If the former, the action is assumed
* to be located within the current controller.
* @return string output
*/
public function execute($route)
{
$get = $_GET;
ob_start();
$this->forward($route, false);
$out = ob_get_clean();
$_GET = $get;
return $out;
}
public function actionDo($id)
{
echo 'actionDo #'.$id;
}
}
@doonfrs
Copy link

doonfrs commented Aug 20, 2013

good , but what about ajax calls requested by "/hmvc/do/id/123" ??
HmvcController will swallow them ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment