Model

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()
 
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');
}
 
I think he copied this from an other controller and this should be getPollModel:D
 
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');
		}
	}
?>
 
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.
polltc.png
 
Top Bottom