在来自 class 的包含文件中设置 class 类型的 $this

Set class type of $this in included file from class

我有自己设计的标准 mvc 东西。

我在其中渲染了模板文件,其中可以通过 $this 引用控制器 class 以用于某些功能以渲染不同的视图等...

在我看来,我有这样的代码:

<img  alt="<?= $record->image ? $record->image->description:'' ?>"
      src="<?= $record->image ? $this->getImagePath($record->image):'' ?>">

当以这种方式用于代码完成时,eclipse 中是否有设置 $this 对象类型的方法?

在你包含的文件的头部放置一个像这样的评论

<?php
/**
 * @var $this \Lib\TourTripRender
 */
?>

现在 $this 应该可以正确自动完成