actions in separte files as class

Hi

i was going through tutorial about separating actions from controller by putting them in separate file

for my case

i removed actionIndex from SiteController(default installation)

and create new file protected/controllers/site/IndexAction.php

what should i put in public function run(){

}

copying and pasting indexAction code from controller doesn’t work.

You can use your reciclable action in this way:




class SpecialController extends CController {


    public function actions() {

        return array(

            'someAction' => array(    /* index.php?r=special/someAction */

                'class' => 'ext.actions.YourParticularAction',

                'parameterName' => 'value'

            ),

            'someStuff' => array(    /* index.php?r=special/someStuff */

                'class' => 'ext.actions.YourParticularAction'

            ),

            ...

        );

    }


}



Or alert your controller adding new actions by hand:




<?php


class YourclassController extends Controller {


    public $layout = '//layouts/column2';

    private $_model;


    public function actions() {

        return array(

            'aclist' => array(

                'class' => 'ext.YourAmathingAction',

                'model' => 'YourModel', /* ... if you want to pass a model */

                'say' => '33' /* ... if you want to pass a value */

            ),

        );

    }



that means:




<?php


class YourAmathingAction extends CAction {


    public $model;

    public $attribute;


    public function run() {

        $yourVar = ....

        /* from here you can read $this->model or $this->say ... or variable you pass from the controller */

        echo CJSON::encode($yourVar);

    }


}