开发者

Is there a way to not override the entire property with a sub model in Kohana?

I have the following chain of Models:

Model_Auth_User
Model_Module_Us开发者_开发技巧er
Model_App_User
Model_User

...where Model_User is the model I'm actually using and it's just a dummy class, while the others all have functionality.

My problem is that in Model_App_User I want to add a column to the model, say employee_flag. I need to add it to _labels, _table_columns and possibly others. Of course, if I put the following in Model_App_User:

 protected $_labels = array(
      'employee_flag' => 'Employee Flag',
 );

the entire array of labels is overwritten. Not what I want.

Once option I thought of was to add a property called _override_properties which I would process on initialize and merge with the properties in the object. But this fails as well because if I use it's in Model_Module_User it will overwrite whatever I've put in Model_App_User.

What other options are there?


There's 2 solutions to this. You can change the way ORM works by defining your labels in a method called labels. I guess it would be something like this:

public static function labels ()
{
    return array
    (
        'name' => 'First Name'
    );
}

Then in your child classes, it would be as easy as:

public static function labels ()
{
    $labels = parent::labels();

    // Add new or modify labels.
    $labels['last'] = 'Last Name';

    return $labels;
}

You'll need to modify how ORM retrieves the labels for this to work. If you don't have the time to modify how ORM works then Zahymakas solution of adding to the array in the child __construct is a good compromise.


What about $this->_labels['employee_flag'] = 'Employee Flag';?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜