Where This Code Belongs? MVC & ORM
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.
精彩评论