Widget Action provider parameters?

is it possible pass parameters to action provider widget?




In cotroller:


public function actions(){

        return array(

           // naming the action and pointing to the location

           // where the external action class is

           'comment.'=> array(

                'class'=>'application.components.pack.comments.CommentActionProvider',

                'owner'=>$this->loadModel(),

           )


        );

    }



Action provider widget




class CommentActionProvider extends CWidget

{	

	

	public static function actions()

	{

		return array (

			// naming the action and pointing to the location

			// where the external action class is

			'create' => 'application.components.pack.comments.actions.create',

		);

		

	}


}



i dont know how to catch the parameter "owner".

any ideas?

I think owner should be a public property of your action class in application.components.pack.comments.actions.create.

Yep, this is supposed to work (see here) but it’s not working for me!

CAction:


class saveJpg extends CAction{

    public $filepath;

    

    public function run(){

        $filepath = $this->filepath;

        print "OK: $filepath";          

    }

}

Widget (relevant part only):


public static function actions()

{

    return array(

       'saveJpg'=>'application.extensions.myext.actions.saveJpg',

    );

}

Client code Controller (relevant part only):


public function actions()

{

    return array(

        'myext.'=> array(

            'class'=>'application.extensions.myext.Myext',

            'filepath'=> 'something'

        )

    );

}

Calling url //localhost/mysite/mycontroller/myext.saveJpg prints ‘OK’ without ‘something’ :(

You could try some framework debugging (also a good oportunity to learn more about the internal mechanics). I would temporarily add some print_r() to some framework files - do not forget to remove them right after!

In your case i’d look at web/CController.php around line 430: createActionFromMap(). From looking at that code i’d say, it should merge all parameters into $config - but maybe somethings wrong there.

I solved the issue. The right way to configure the controller is:


public function actions()

{

    return array(

        'myext.'=> array(

            'class'=>'application.extensions.myext.Myext',

            'saveJpg'=>array(

                'filepath'=> 'something'

            )

        )

    );

}

Cool, congrats :)

Could you maybe write that up in a manual comment or create a wiki for it? I think, this question already came up several times and the solution is not really documented clearly. Or maybe change your bug report to rather update the class reference and include a simple example.

Done: see here.