0

I have a method in a model and I need the array of state variables. In controller it's easy, simply get an $model object and get the array with

$state = $model->getState();

But in a model all my test always get an error 0 or 503:

class MyModel extends ListModel
{
...
    public function setFiltrosActivos()
    {
        $state = $this->getState();  // 503 error
    }
}

Please, how can I get the state variables in a method inside a model?

2
  • Issue not reproducible. Post the error message and stack trace.
    – Sharky
    Commented Jan 15 at 7:21
  • Sorry, I only receive a server error with 503 Service Unavailable. The server is temporarily busy, try again later!. No stack trace
    – Peli
    Commented Jan 15 at 12:08

1 Answer 1

0

Finally I chose to move the entire method from the model to a helper and perform the logic there. Now it's working fine. Thank you.

$model  = Factory::getApplication()->bootComponent('com_mycomponent')->getMVCFactory()->createModel('mymodel', 'Site');
$state = $model->getState();
4
  • Please accept your answer as the chosen solution.
    – Irata
    Commented Jan 16 at 21:20
  • 1
    Glad you solved your issue. But this is a bad answer. It does not explain how or why it works and why original code did not work. Calling getState() from within the model should work without issues - it does across the entire CMS. The only thing that could be causing the issue is calling the the method inside populateState() method which would result in recursion, as per documentation.
    – Sharky
    Commented Jan 17 at 7:01
  • Really I don't know why this problem has occurred. Your answer have complete sense., thanks again.
    – Peli
    Commented Jan 18 at 5:25
  • @Irata. Yes, I tried to accept the answer yesterday but it is necessary to wait 24 hours according to forum rules.
    – Peli
    Commented Jan 18 at 6:14

Your Answer

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

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