I am using Microsoft Visual Code for custom Joomla development. The below code is from one of the controller php file.

Public function savecontact(){
    Joomla\CMS\Session\Session::checkToken() or die( 'Invalid Token' );
    $model = $this->getModel('book');

    if ($model->store()) {
        $msg = Joomla\CMS\Language\Text::_( 'JSMS_BOOKV_BOOKSAVESUCCESS' );
        $msg_type = "message";
    } else {
        $msg = Joomla\CMS\Language\Text::_( 'JSMS_BOOKV_BOOKSAVEFAIL' );
        $msg_type = "error";

The above code is trying to use the method defined inside the model. Since the model is called as getModel('book') Visual Code is not able to interpret the methods defined in the model and it is throwing error as Undefined method 'store'.

enter image description here

I understand this is not an actual error, it is only a problem in Visual Code display. To me it is annoying to see these type of errors in every controller file.

How this can be remediated so that Visual Code should not throw this as an error?

1 Answer 1


One way is to explicitly specify the class with an inline doc block:

/** @var \Path\To\BookModel $model */
$model = $this->getModel('book');
  • This resolves the current problem. The path you mentioned looks like static... even I give a wrong path (empty) also works. It looks like we are fooling the vc editor... correct? Aug 31, 2021 at 8:12
  • No, the intention is to use a valid class name. The path I've given is an example of a fully classified class name. You should change it to your model's class name. This way the error will go away and all editor features will continue working.
    – Sharky
    Aug 31, 2021 at 8:25
  • Great. Now I understand. This works. Aug 31, 2021 at 8:31

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.