开发者

Where This Code Belongs? MVC & ORM

开发者 https://www.devze.com 2023-03-15 19:49 出处:网络
I\'m reading unofficial Kohana 3.0 docs at the moment. Where this code belongs? In controller or in model (class Model_MyName extends ORM model?)? I think that it should go in model. Am I right? If th

I'm reading unofficial Kohana 3.0 docs at the moment. Where this code belongs? In controller or in model (class Model_MyName extends ORM model?)? I think that it should go in model. Am I right? If that so... why is it on controller and how to implement it in model (do I need to change somet开发者_如何转开发hing in save() method?)?

$user = ORM::factory('user', 1);
$user->name = 'Joe';
$user->values($_POST);
if ($user->check()) {
    $user->save();
} else {
    $errors = $user->validate()->errors();
}

Code taken from here under "Model Validation".


It belongs to the controller. This code is clearly using the 'user' model from ORM factory.

$user is an instance of the 'user' model. In your case the models are being provided by Kohana's ORM.

0

精彩评论

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

关注公众号