Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Method not found in \Phalcon\Mvc\Model PhpStorm

Hello

$article = Articles::findFirst(1);
$article->getTitle();

Method findFirst return \Phalcon\Mvc\Model, so it is true that Method not found, but Articles has this method. How can we cast \Phalcon\Mvc\Model to Articles ?

image

This code works, but it is very inconvenient that the tips (autocomplete) from the IDE do not work.. Thank you.

edited 10d ago

Have you referenced the stubs from phalcon devtools?

Model::findFirst() should be hinted, but Robots::findFirstByName() will be not because it's a magic method



317
edited 10d ago

Yes, I have /Users/user/Phalcon/ide-stubs-master in Language & Frameworks > PHP > Include Path and in External Libraries this folder is shown

Articles.class

    <?php

    namespace News\Models;

      class Articles extends \Phalcon\Mvc\Model
      {

    /**
     * @var string
     */
    protected $title;

    /**
     * @return string
     */
    public function getTitle(): string
    {
        return $this->title;
    }

    /**
     * @param string $title
     */
    public function setTitle(string $title)
    {
        $this->title = $title;
    }

    /**
     * @return string
     */
    public function getSource()
    {
        return 'Articles';
    }

    }


112.0k
Accepted
answer

Add firstFind method in Articles class and user phpdoc.