mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
490835633c
commit
3eafee7799
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user