We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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 Nov '17

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



2.5k
edited Nov '17

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';
    }

    }


145.0k
Accepted
answer

Add firstFind method in Articles class and user phpdoc.