class SomeController extends Controller
{
…
public function yourMethod($arg1, $arg2 = null)
{
…
}
}
…
//and for instance, somewhere in your view
$this->yourMethod($model, 'value')
EDIT: or do you mean incorporating actions for other controllers, or the main controller?
class SomeController extends Controller
{
…
public function beforeAction($action)
{
if ($action=='MyMethod2') <"attach from SomeMethodsClass">
}
public function actionMyMethod1()
{
…
}
public function actionMyMethod2()
{
$this->myMethod3();
}
}
class SomeMethodsClass //extends Controller
{
…
public function myMethod3()
{
$this->render('index');
}
public function myMethod4()
{
$this->render('index2');
}
}
class SomeController extends Controller
{
public function beforeAction($action)
{
switch ($action->id)
{
case 'MyMethod2':
$this->attach( 'someMethods', array(
'class' => 'app.behaviors.SomeMethodsBehavior',
// more initialization if needed
));
break;
}
return parent::beforeAction($action);
}
public function actionMyMethod1()
{
…
}
public function actionMyMethod2()
{
// myMethod3 defined in "app.behaviors.SomeMethodsBehavior"
$this->myMethod3();
}
}
I remember a state machine extension that does dynamic behavior attachment and detachment depending on state transitions. It might be possible to re-use this extension if you look at an controller as an state machine like this: