Yii Framework Forum: Related tables updated - a Behavior - Yii Framework Forum

Jump to content

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

Related tables updated - a Behavior Rate Topic: -----

#1 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 30 April 2010 - 08:01 AM

Hi, I've just discovered that Yii needs an Object to updated related tables when you save/update the main one. I've looked into extensions page where there are:
* http://www.yiiframew...nsion/relation/ a widget to update related tables
* http://www.yiiframew...ncedarbehavior/ a behavior to do same thing
Now I'd prefer to use a component behavior, but CAdvancedArBehavior has only MANY_MANY capability, it doesn't work with BELONGS_TO and HAS_ONE, as widget do. Further more, the widget seems a cleaner code.
So I would like to write a behavior taking code from the widget. Now my questions:
1. Does exist a component behavior that makes those update?

2. After I've created a behavior and attached to my Active model with:
public function behaviors(){
          return array( 'MyBehavior' => array(
            'class' => 'path.to.MyBehavior'));
          }

How can I access to Behavior's methods from Controller? I've tried $this->MyBehavior->method() but it does nothing

3. If I create a method that exists in model where behavior is attached, for example save() method, it overwrites model's one?
0

#2 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 30 April 2010 - 05:37 PM

If you want to call a method defined in the behavior, you call that method like a regular one.

class MyBehavior extends CBehavior
{
    public function TheMethod()
    { ... }
}

// suppose the behavior is attached to the object in $myObject.
// call the behavior's method TheMethod() like this (if $myObject does not have a method
// TheMethod):
$myObject->TheMethod();

// or like this (mind the case, it must exactly match the behavior name) if $myObject already has a method TheMethod():
$myObject->myBehaviorName->TheMethod()


So when you tried $this->Mybehavior->method() you were on the right track. If nothing happens then your behavior's method probably has an error. If yii would find an error with the behavior then an exception is thrown and you'd see a message.
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