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

Model

DroidHost

Well-known member
#1
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()
 

Shadab

Well-known member
#2
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');
}
 

Kier

XenForo Developer
Staff member
#6
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');
		}
	}
?>
 

DroidHost

Well-known member
#7
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.