2

Which is the correct/best method of calling model methods inside view.html.php.

Method 1

$mydata = $this->get('MyData') ;

Method 2

$model = $this->getModel() ;
$mydata = $model->getMyData() ;

I feel is the Method 2 is the best because I can even pass arguments to the model (if required).

1 Answer 1

2

I think $mydata = $this->get('MyData'); is the best way to call model's functions if you don't need to pass any argument.

Model's function are already available in the MVC view logic and using the second method to reload the model feels redundant to me. Usually I write my component's model functions using only arguments passed trough GET or POST and write other functions, that needs args, in the Helper class.

1
  • Calling getModel does actually reload the model it just returns a reference to the instance. Nov 20, 2015 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.