php - Call model function inside view joomla -


how can call different models , functions in joomla 2.5 view ?

model: settings.php

// import joomla modelitem library jimport('joomla.application.component.modelitem');  class urcmodelsettings extends jmodelitem {            public function getsettings($user_id = '')     {         $user = jfactory::getuser();             $user_id=$user->id;          $db =& jfactory::getdbo();         $query = $db->getquery(true);         $query->select('*');         $query->from('#__settings_urc');         $query->where('user_id = '. (int) $user_id);         $db->setquery($query);         return  $db->loadobjectlist();     } } 

view: view.html.php

// import joomla view library jimport('joomla.application.component.view');  /**  * html view class helloworld component  */ class urcviewurc extends jview {            // overwriting jview display method     function display($tpl = null)      {         $model = $this->getmodel('settings');         $datas = $model->getsettings();          // check errors.         if (count($errors = $this->get('errors')))          {                 jlog::add(implode('<br />', $errors), jlog::warning, 'jerror');                 return false;         }         // display view         $user = jfactory::getuser();         if($user->id!=0)         {             parent::display($tpl);         }         else         {             echo "you have not permission page";         }                    } } 

i using getmodel('settings'); works in controllers it's give me error in view.

notice: undefined index: settings in c:\wamp\www\joomla\libraries\joomla\application\component\view.php on line 413  fatal error: call member function getsettings() on non-object in c:\wamp\www\joomla\components\com_urc\views\urc\view.html.php on line 40 

you can try jmodel class calling specific model in view.

$model = jmodel::getinstance('model_name', 'model_class_prefix');  

for example:

$model = jmodel::getinstance('settings', 'urcmodel'); $settings = $model->getsettings (); 

hope help.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -