ENHANCEMENT: Added ModelAsController::controller_for() to link a SiteTree object to its controller.

From: Andrew Short <andrewjshort@gmail.com>

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88479 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew Short 2009-10-11 00:07:02 +00:00 committed by Sam Minnee
parent 490835633c
commit 3eafee7799

View File

@ -9,6 +9,24 @@
*/
class ModelAsController extends Controller implements NestedController {
/**
* Get the appropriate {@link ContentController} for handling a {@link SiteTree} object, link it to the object and
* return it.
*
* @param SiteTree $siteTree The SiteTree object to find a controller for.
* @param string $action The optional action that was requested, so that action-specific controllers work.
* @return ContentController
*/
public static function controller_for(SiteTree $siteTree, $action = null) {
$controller = "{$siteTree->class}_Controller";
if($action && class_exists($controller . '_' . ucfirst($action))) {
$controller = $controller . '_' . ucfirst($action);
}
return class_exists($controller) ? new $controller($siteTree) : $siteTree;
}
public function handleRequest($request) {
$this->pushCurrent();
$this->urlParams = $request->allParams();