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

Model

Discussion in 'XenForo Development Discussions' started by DroidHost, Feb 3, 2011.

  1. DroidHost

    DroidHost Well-Known Member

    How to link a controller to a specific Model ?

    and how I can use a Xenforo Model inside my Controller ?

    I use this
    PHP:
    <?php

        
    class HelloWorld_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
        
    {
            public function 
    actionIndex()
            {
                
    $pollModel $this->_etPollModel();
                
    $poll $pollModel->getPollByContent('thread'1);
                if (
    $poll)
                {
                    
    $poll $pollModel->preparePoll($poll$threadModel->canVoteOnPoll($thread$forum));
                    
    $poll['canEdit'] = $threadModel->canEditPoll($thread$forum);
                }

                
    $sndan = array( 'MyName'=>'Ali Hussain Bozaid' ,
                                
    'post'=>array('title'=>'Ahmed') ,
                                
    'poll' => $poll,
                );

                return 
    $this->responseView('HelloWorld_ViewPublic_Index''helloWorld_view',$sndan);
            }

        }
    ?>
    but it give me this message
    Call to undefined method HelloWorld_ControllerPublic_Index::_etPollModel()
     
  2. Shadab

    Shadab Well-Known Member

    Well, you have to define that method in your class...
    PHP:
    /*
     * @return Your_Model_Class_Name
     */
    protected function _getYourModel()
    {
        return 
    $this->getModelFromCache('Your_Model_Class_Name');
    }
     
  3. ragtek

    ragtek Guest

    I think he copied this from an other controller and this should be getPollModel:D
     
  4. Kier

    Kier XenForo Developer Staff Member

    Edited to reflect that :)
     
  5. Shadab

    Shadab Well-Known Member

    Doh! :p

    In that case, the model classname would be: XenForo_Model_Poll.
     
  6. Kier

    Kier XenForo Developer Staff Member

    PHP:
    <?php

        
    class HelloWorld_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
        
    {
            public function 
    actionIndex()
            {
                
    $pollModel $this->_getPollModel();
                
    $poll $pollModel->getPollByContent('thread'1);
                if (
    $poll)
                {
                    
    $poll $pollModel->preparePoll($poll$threadModel->canVoteOnPoll($thread$forum));
                    
    $poll['canEdit'] = $threadModel->canEditPoll($thread$forum);
                }

                
    $sndan = array( 'MyName'=>'Ali Hussain Bozaid' ,
                    
    'post'=>array('title'=>'Ahmed') ,
                    
    'poll' => $poll,
                );

                return 
    $this->responseView('HelloWorld_ViewPublic_Index''helloWorld_view',$sndan);
            }

            
    /**
             * @return XenForo_Model_Poll
             */
            
    protected function _getPollModel()
            {
                return 
    $this->getModelFromCache('XenForo_Model_Poll');
            }
        }
    ?>
     
  7. DroidHost

    DroidHost Well-Known Member

    Huh ...
    [_etPollModel();] it was correct . but because I am trying to get it work I was doing trials/err so I can understand the framework
    and accidentally removed the G !

    I modify it more and now
    it is working ..
    thanks all.
    [​IMG]
     

Share This Page