Search code examples
phpmodel-view-controllerjoomlajoomla3.0joomla-extensions

Edit Form Doesn't work in joomla


I'm building a Joomla component and trying to create a edit form backend but data doesn't show in text box this is my view.html

  protected $item;
protected $form;

function display($tpl=null)
{

    $this->item = $this->get('Item');
    $this->form = $this->get('Form');


    $this->addToolbar();
    parent::display();
}

my model :

    class ComModelCat extends JModelAdmin
{
     public function getTable($type='cat',$prefix='comTable',$config=array())   
     {
         return JTable::getInstance($type,$prefix,$config)  ;
     }
     protected function loadFormData()
     {
         //read data for load foram 
         $data=JFactory::getApplication()->getUserState('com_Com.edit.cat.data',array());
         if(empty($data))
         {
             return $data;
         }
         return $data;
     }
     public function getForm($data=array(),$loadData=true)
     {
         $form=$this->loadForm('com_lab.cat','cat', array('control'=>'jform','load_data'=>$loadData));
         return $form;
     }
}

and my controller :

    class ComControllerCat extends JControllerForm
{
    protected $viewlist='cats';

     public function __construct()
     {
        parent::__construct();
     }
}

and also i used var_damp($this->item); and data come from my model but doesnt show in text box and i used $this->form->renderField('id')


Solution

  • change

       if(empty($data))
             {
                 return $data;
             }
             return $data;
    

    to

     if (empty($data))
            {
                $data = $this->getItem();
            }
    
            return $data;