Resources: SilverStripe

Access Controller function from Model

14 July 2014

Got functionality that lives in the controller that you need to access from an object's Model? Let's say your function is called MyFunction, this is how it would play out:

MyObjectClassName.php:

// return the function of the same name, from the controller
public function MyFunction(){
   $class = $this->ClassName . "_Controller";
   $controller = new $class($this);
   return $controller->MyFunction();
}

Tags: , ,

Let's work together