Yii Framework Forum: Self contained Ajaxian Widgets! - Yii Framework Forum

Jump to content

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

Self contained Ajaxian Widgets! Rate Topic: ***** 1 Votes

#1 User is offline   phiras 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 10-September 09
  • Location:Amman

Posted 16 February 2010 - 03:39 PM

Hi guys,

Is it possible to build a Widget that could handle its ajax requests alone. without the need to write controller actions to handle those requests ? I think the answer is no.

According to the APIs,"A widget is a self-contained component that may generate presentation based on model data. It is a micro-controller that embeds into the controller-managed views. Compared with controller, a widget has neither actions nor filters. "

My point is :
How could the widget be some sort of controllers if it couldn't deal with user interactions ? in the other hand, how could a widget be self-contained if we need to write some code outside to treat ajax requests.

What do you think ?

- Phiras
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 16 February 2010 - 03:45 PM

This is a good question. We could support such truly self-contained widgets, but the problem is that it would complicate creating the widget as well as their usage.

A not so self-contained yet simpler approach would be to implement the ajax action code in the widget class and ask the user of the widget to call this method in their appropriate controller actions. As an example, you may take a look at the new CActiveForm (in svn trunk only) which performs server-side validation via AJAX.
0

#3 User is offline   phiras 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 10-September 09
  • Location:Amman

Posted 16 February 2010 - 03:58 PM

View Postqiang, on 16 February 2010 - 03:45 PM, said:

This is a good question. We could support such truly self-contained widgets, but the problem is that it would complicate creating the widget as well as their usage.


Supporting such thing in a subclass of CWidget wouldn't affect users who want to create regular widgets. and will support the idea and could be very cool.

Thank you for your answer and thank you for the good work!
0

#4 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 04 March 2010 - 04:31 AM

I'd like to see this... so much... :P
0

#5 User is offline   Mike 

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

Posted 04 March 2010 - 05:35 AM

How could a route to such a widget action look?

These actions would have to be static widget methods, as no widget instance will exist.
0

#6 User is offline   Hwangar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 24-September 09
  • Location:Bilbao, Spain

Posted 04 March 2010 - 06:46 AM

I see no problem in that... because inside the widget all actions should be well-known

The thing is what you said, it has to be coded in the core, I see no means to implement something external to give this funcionality but I see that as a MUST-HAVE if you want to implement totally indepentend widgets
0

#7 User is offline   Mike 

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

Posted 04 March 2010 - 07:26 AM

The changes would not be many. If widget routes look like e.g. "?r=widget:MyWidget/someMethod" only CWebApplication::processRequest would have to be changed to handle those routes differently. And maybe CUrlManager would need some changes to make sure, these routes are created/parsed properly.

But not sure, if this route pattern is really appropriate.
0

#8 User is offline   Mike 

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

Posted 04 March 2010 - 07:31 AM

Oh, one important thing will make things difficult: authentication is now coupled tightly to controller actions. You'd have to add similar auth checks for your public widget actions to make them really useful.
0

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