Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8116169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:43:55+00:00 2026-06-06T03:43:55+00:00

So I have a model like this: class MyClass { public $customer = null;

  • 0

So I have a model like this:

class MyClass 
{
     public $customer = null;
     public $address = null;
}

And a form like this:

class MyForm extends CFormModel
{ 
     public $customer = null;
     public $address = null;

     /**
     * Declares the validation rules.
     */
     public function rules()
     {
         return array(
         array('customer, address', 'required'),
         array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
     );

     /**
      * Declares customized attribute labels.
      * If not declared here, an attribute would have a label that is
      * the same as its name with the first letter in upper case.
     */
     public function attributeLabels()
     {
         return array(
               'verifyCode'=>'Verification Code',
         );
     }
}

What I would like to do, is extend the model in my form, but you can’t do multiple object inheritance in PHP.

How would I do this, so as to avoid duplicating all of the field properties of model in form?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:44:00+00:00Added an answer on June 6, 2026 at 3:44 am

    Use of Component Behavior

    A component supports the mixin pattern and can be attached with one or several behaviors. A behavior is an object whose methods can be ‘inherited’ by its attached component through the means of collecting functionality instead of specialization (i.e., normal class inheritance). A component can be attached with several behaviors and thus achieve ‘multiple inheritance’.

    Behavior classes must implement the IBehavior interface. Most behaviors can extend from the CBehavior base class. If a behavior needs to be attached to a model, it may also extend from CModelBehavior or CActiveRecordBehavior which implements additional features specifc for models.

    To use a behavior, it must be attached to a component first by calling the behavior’s attach() method. Then we can call a behavior method via the component:

    // $name uniquely identifies the behavior in the component
    $component->attachBehavior($name,$behavior);
    // test() is a method of $behavior
    $component->test();
    

    An attached behavior can be accessed like a normal property of the component. For example, if a behavior named tree is attached to a component, we can obtain the reference to this behavior object using:

    $behavior=$component->tree;
    // equivalent to the following:
    // $behavior=$component->asa('tree');
    

    A behavior can be temporarily disabled so that its methods are not available via the component. For example,

    $component->disableBehavior($name);
    // the following statement will throw an exception
    $component->test();
    $component->enableBehavior($name);
    // it works now
    $component->test();
    

    It is possible that two behaviors attached to the same component have methods of the same name. In this case, the method of the first attached behavior will take precedence.

    When used together with events, behaviors are even more powerful. A behavior, when being attached to a component, can attach some of its methods to some events of the component. By doing so, the behavior gets a chance to observe or change the normal execution flow of the component.

    A behavior’s properties can also be accessed via the component it is attached to. The properties include both the public member variables and the properties defined via getters and/or setters of the behavior. For example, if a behavior has a property named xyz and the behavior is attached to a component $a. Then we can use the expression $a->xyz to access the behavior’s property.

    More reading:
    http://www.yiiframework.com/wiki/44/behaviors-events
    http://www.ramirezcobos.com/2010/11/19/how-to-create-a-yii-behavior/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object model like this: public class MyClass { int TheProp {get;set;}
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
I'm using MVC3 and I have a model like this: public class Foo {
I have Model class like this class ModelName { public static void createTable(SQLiteDatabase db){
I have a class setup like this public class MyCLass { //... public IList<MyInnerClass>
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model.py like this: class EventTypeCategory(models.Model): name = models.CharField(max_length=50, verbose_name=Name) user =
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.