1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is there any advantage of using the following way to fetch Model?

Discussion in 'XenForo Development Discussions' started by TheBigK, Aug 31, 2015.

  1. TheBigK

    TheBigK Well-Known Member

    Can someone tell me if there's any advantage in using any of the following ways to fetch a model?

    PHP:
    public function actionIndex()
    {
     
    $myModel $this->_getMyModel()
    }
    protected function 
    _getMyModel()
    {
    return 
    $this->getModelFromCache('MyAddon_Model_MyModel');
    }
    and
    PHP:
    public function actionIndex()
    {
     
    $myModel $this->getModelFromCache('MyAddon_Model_MyModel'); 
    }
     
  2. batpool52!

    batpool52! Well-Known Member

    None really. If the model is being used twice in different functions then I use the first method
    PHP:
    public function actionIndex()
    {
        
    $myModel $this->_getMyModel()
    }
    protected function 
    _getMyModel()
    {
        return 
    $this->getModelFromCache('MyAddon_Model_MyModel');
    }
    and if the model is being used just once then I use the second method
    PHP:
    public function actionIndex()
    {
        
    $myModel $this->getModelFromCache('MyAddon_Model_MyModel');
    }
     
    TheBigK likes this.
  3. TheBigK

    TheBigK Well-Known Member

Share This Page