使用文件模板在Netbeans中创建新的PHP类时的缩进

时间:2011-08-04 10:13:42

标签: templates netbeans

我可能遗漏了一些东西,但我有以下问题:

我正在使用Netbeans IDE 7.0。

我已经为新的PHP类创建了一个模板,但是当我尝试创建一个新类时,我创建的模板插入时没有任何缩进。

示例:

模板:

<?php
/**
 * Description of ${name}
 *
 * @author ${user}
 */
include_once("class_functions.php");

class ${name} {
    //Class properties

    function __construct() {
        //Constructor
    }

    public function __get($name) {
        if(method_exists($this, 'get' . ucfirst($name))) {
            return $this->{'get' . ucfirst($name)};
        } else {
            if (property_exists($this, $name)) {
                $this->{$name} = $value;
            } else {
                throw new Exception("Undefined property '$name'.");
            }
        }
    }
}

但是当我使用这个模板时,新类被创建为:

<?php
/**
 * Description of ${name}
 *
 * @author ${user}
 */
include_once("class_functions.php");

class ${name} {
//Class properties

function __construct() {
//Constructor
}

public function __get($name) {
if(method_exists($this, 'get' . ucfirst($name))) {
return $this->{'get' . ucfirst($name)};
} else {
if (property_exists($this, $name)) {
$this->{$name} = $value;
} else {
throw new Exception("Undefined property '$name'.");
}
}
}
}

有谁知道我做错了什么?

非常感谢任何帮助!提前谢谢。

2 个答案:

答案 0 :(得分:1)

似乎如果使用标签保存模板,它将剥离它们。使用用于缩进的空格保存模板,它们将被过滤到制表符中,或者作为netbeans首选项的空格留下。

您可能还会遇到语法问题,有时会通过渲染。

正如我之前所说,alt + shit + f是netbeans的朋友(自动格式)

答案 1 :(得分:-1)

解决方法:

创建您的OWN模板文件并将其添加到Netbeans文件模板。 所有的缩进都神奇地开始工作......

文件模板对话框 - &gt;添加