Yii Framework Forum: Widget Action provider parameters? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Widget Action provider parameters? Rate Topic: -----

#1 User is offline   xavicai 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 05-May 11

Posted 27 May 2011 - 02:33 AM

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?
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 28 May 2011 - 04:48 AM

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

#3 User is offline   Attilio 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 10-May 11
  • Location:Bari, Italy and Guatemala, Guatemala

Posted 02 June 2011 - 08:40 PM

View PostMike, on 28 May 2011 - 04:48 AM, said:

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' :(
Extension yii-jpegcam: embed a webcam and take photos
0

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 03 June 2011 - 01:30 AM

View PostAttilio, on 02 June 2011 - 08:40 PM, said:

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.
0

#5 User is offline   Attilio 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 10-May 11
  • Location:Bari, Italy and Guatemala, Guatemala

Posted 05 June 2011 - 09:48 PM

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'
            )
        )
    );
}

Extension yii-jpegcam: embed a webcam and take photos
2

#6 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 06 June 2011 - 02:25 AM

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.
0

#7 User is offline   Attilio 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 10-May 11
  • Location:Bari, Italy and Guatemala, Guatemala

Posted 06 June 2011 - 12:39 PM

Done: see here.
Extension yii-jpegcam: embed a webcam and take photos
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users