一直用Netbeans寫php,從來沒配置過模板,模板配置好,可以省很多事,而且,顯得很專業,今天到netbeans官方網站找了一些東西,配置好模板,方便開發。
新建php文件時:
<?php
/**
* Encoding : UTF-8
* Created on : 2009-10-23 14:48:40 by smallchicken , [email protected]
*/
?>
工具--模板--打開php裏面的--“PHP 文件”,在編輯器中打開,
好,可以編輯模板文件。
當然,如果要寫入時間和文件名之類的變量需要單獨配置變量。
<?php
/**
* Encoding : ${encoding}
* Created on : ${date} ${time} by ${author} , ${email}
*/
?>
變量需要在 工具--模板--用戶配置屬性--User.properties 在編輯器中打開
[email protected]
author=smallchicken
${date?date?string("yyyy-m-d")}
${time?time?string("H:i:s")}
寫入變量就可以了。
日期和時間的格式和php相同,
變量名字可以自己定義。
官方的模板變量名列表:
http://wiki.netbeans.org/FaqTemplateVariables
Can you give me a list of all the predefined variables for templates, like ${user} and ${date}?
- ${date} inserts the current date, in this format: Feb 16, 2008
- ${encoding} inserts the default encoding, such as: UTF-8
- ${name} inserts the name of the file.
- ${nameAndExt} inserts the name of the file, together with its extension.
- ${package} inserts the name of the package where the file is created.
- ${time} inserts the current time, in this format: 7:37:58 PM
- ${user} inserts the user name.
- ${project.license} based on the value (e.g., 'CDDL'), the license header is found and is inserted into the template.
- ${project.name} inserts the project name
- ${project.displayName} inserts the project displayname
For more details, go here.
How do I override those predefined variables?
- Go to Tools | Templates.
- Scroll to the end of the Template Manager and expand 'User Configuration Properties'.
- Select 'User.properties' and click 'Open in Editor'.
- Now you can add the above and set your own value, for example:
Now, whenever you have ${user} in a file template, you will find the above value generated into the file that you create using that template.
Note: The ${date} variable is of type String, not type Date. You have to cast it to a Date type then do the format. For example, to show the year only, do this:
${date?date?string("yyyy")}其實還是蠻好配置的