MVC: Calling a model from a view
Posted: Thu Feb 21, 2008 12:14 am
Hi,
What I trying to do: I created a login view which the user access by clicking on a link on my navigation bar. The link I created using the joomla administration site (see attached image). Joomla creates a link which points directly to the view and NOT to the controller. The below code now tries to oull the data model 'language' into the view - without any success.
Just to test it I created an external link to my component using the 'option' and 'task' parameter.
With that approach the controller does the job (see code below):
This approach does the trick, the model is being pulled in/assigned to the view. As I obviously want to be able to use the nifty backend of joomla properly, I need to know how to assign a model to a view in the view itself.
Thanks,
Uwe
What am I missing?
Thanks a lot,
Uwe
What I trying to do: I created a login view which the user access by clicking on a link on my navigation bar. The link I created using the joomla administration site (see attached image). Joomla creates a link which points directly to the view and NOT to the controller. The below code now tries to oull the data model 'language' into the view - without any success.
Code: Select all
class xyzViewLogin extends JView {
function display($tpl = null) {
$model_language = &$this->getModel('language');
$model_login = &$this->getModel('login');
$this->assignRef('label',$model_language->labels);
$this->assignRef('userName', $model_login->userName);
parent::display($tpl);
}
Code: Select all
index.php?option=com_ehive&task=login
Code: Select all
function login() {
$session = JFactory::getSession();
$document =& JFactory::getDocument();
$viewName = JRequest::getVar('view','login');
$model_language = &$this->getModel('language');
$viewType = $document->getType();
$view = &$this->getView($viewName, $viewType);
if (!JError::isError( $model_language )) {
$view->setModel( $model_language, true );
}
$view->setLayout('login');
$view->display();
}
Thanks,
Uwe
What am I missing?
Thanks a lot,
Uwe