2

在 PDT 我可以做

/* @var $this MyClass */

并且 Eclipse 将使用它来进行自动完成、建议等......它在模板文件中很有用,这些模板文件被包含在模板引擎的类的函数中。

Aptana Studio 3 是否有同等功能?

我也试过

/** @var $this MyClass */

/** @var MyClass $this */

编辑

我正在评估 Aptana 的使用,它比 Eclipse + PDT 有一些优势。因此,“使用另一个 IDE”并不是真正的答案。

$this IDE不会自动将其解析为正确的类,因为它是在类定义之外使用的。

示例用法:

  • 模板.class.php:

    class Template {
        public function render() {
            include 'template.inc.php';
        }
        private function foo() {
            echo 'bar!';
        }
    }
    
  • 模板.inc.php

    <?php /*@var $this Template*/ ?>
    <html>
    <body>
      <?php 
      /* I want that when I type "$this->" the IDE suggests me "foo()" */
      $this->foo(); 
      ?>
    </body>
    </html>
    
4

2 回答 2

1

升级到 3.0.7。它似乎在该版本中可用。

http://jira.appcelerator.org/browse/APSTUD-1714

于 2011-10-25T12:22:25.970 回答
-2

模板的重点是保持逻辑和视图分开,你在那里做的是添加视图逻辑,这样你就不会真正做任何需要的事情。

你想做这样的事情:

<html>
<body>
{TPL.MY_TPL_VAR}
</body>
</html>

然后在你的模板类中,你会有这样的东西:

$myTemplateVars = array('{TPL.MY_TPL_VAR}' => 'This is my content');

foreach($myTemplateVars as $key => $var){
    $output = str_replace($key, $val, $key);
}

return $output;

第二件事是 $this 是 PHP 中预定义的“关键字”,它只能在类中使用,因此您可能希望通过执行以下操作来初始化该类的新实例:

$objTpl = new Template();
$objTpl->yourFunc();

我希望这有帮助 :)

于 2011-10-25T12:24:41.177 回答