1

in my component Centros I have the view and model for Hospitals, working fine. I want to call a general model. general.php located in the models folder.

class CentrosModelGeneral extends JModelItem
{
    protected $general;
    public function getFck()
    {
        if (!isset($this->general))
        {
            $this->general = 'Hello World!';
        }
        return $this->general;
    }
}

I want to access into the general model from my hospìtal component. So, inside my function display() I am trying this:

    $model = JModelLegacy::getInstance( 'general', 'CentrosModel');
    var_dump ($model->get('fck'));

The var_dump gives me a null value. :( What is wrong?. The var_duymp($model); gives me a long StdClass.

object(CentrosModelGeneral)[360]

     protected 'general' => null
      protected '_item' => null
      protected '_context' => string 'group.type' (length=10)
      protected '__state_set' => null
      protected '_db' => 
     protected 'name' => string 'general' (length=7)
     protected 'option' => string 'com_centros' (length=11)
     protected 'state' => 

So, it looks like is working, but i dont know how to call the getFck function..

Any idea?

1 Answer 1

1

Okey this was a stupid question, I just needed to add:

    var_dump ($model->getFck());
1
  • 2
    There are no stupid questions -- well, maybe there are, but this one doesn't need to be labeled as such. Let's make lemonade from lemons here. If you ran into such a hiccup, there is a good chance that others will too. Please take a moment to educate other Joomla users about your discovery, explain why you couldn't see what you needed and why your solution works. This is a real opportunity to help/educate others who aren't experienced with object data. Nov 2, 2018 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.