As I've just started with Joomla component development, this might sound stupid, or might be trivial.
I would like to know if its possible to have different models attached to a view, without using separate controllers?
My intention is actually to use same model for different views.
Thanx in advance...
Yes, you can load any model in the view with
$model = JModel::getInstance('ModelName', 'ComponentNameModel');
OK, got it working.
Basically you just need to check for the 'view' variable in the JRequest class:
if(JRequest::getVar('view') == 'yourtargetview') {
$modelMain = $this->getModel ( 'yourtargetmodel' );
$viewCallback = $this->getView ( 'yourtargetview', 'html');
$viewCallback->setModel( $modelMain, true ); // true is for the default model;
}
And then in your target view class, reference the model functions as follows(notice the second parameter to get call):
$this->targetFieldValue = $this->get('targetMethod', 'targetModel');
Hope it helps...