CakePHP 5.x 的 PhpStorm“未知命名参数”错误

PhpStorm "Unknown named parameter" Error With CakePHP 5.x

提问人:Russell Toris 提问时间:9/27/2023 更新时间:10/24/2023 访问量:72

问:

我最近在 CakePHP 5 中创建了一个新项目,它与 PHP 8.1+ 兼容并接受命名参数。我刚烘焙了一个模型,在控制器中,使用 PhpStorm (2023.1.2) 时,我收到一个突出显示的错误。

请注意,代码本身执行良好,是 PhpStorm 称其为错误。

tutorial/baked 控制器在编辑器中出现以下错误(是一种关系):ComponentshasMany

    public function view(?string $id = null): void
    {
        $unit = $this->Units->get($id, contain: ['Components']);
        $this->set(compact('unit'));
    }

PhpStorm 给了我:

Unknown named parameter 'contain'

在 CakePHP 5 之前,语法是:

    public function view(?string $id = null): void
    {
        $unit = $this->Units->get($id, ['contain' => ['Components']]);
        $this->set(compact('unit'));
    }
蛋糕php phpstorm

评论

0赞 Salines 9/27/2023
戴夫,你安装了 github.com/dereuromark/cakephp-ide-helper
0赞 mark 10/10/2023
请参阅已修复此问题的 github.com/cakephp/bake/issues/944 和相关 PR

答:

0赞 wowDAS 10/24/2023 #1

/ 问题已解决。尝试更新并再次烘焙您的注释cakephp-ide-helperbakecomposer update

然后,您的表类应该具有更新的注释,并且由于更新的注释,PhpStorm错误应该消失了。