加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何设置Eclipse PDT遵循Zend Framework 2编码约定?

发布时间:2020-12-13 16:54:47 所属栏目:PHP教程 来源:网络整理
导读:我正在学习Zend Framework 2.当我按下Ctrl Shift F组合自动格式代码的键时,它显示不像Zend Framework 2编码惯例.请给我一个简单的方法来自动格式化代码遵循 Eclipse 4.4 Luna PDT( PHP开发工具)中的Zend Framework编码约定. 解决方法 我曾经使用Eclipse和PDT
我正在学习Zend Framework 2.当我按下Ctrl Shift F组合自动格式代码的键时,它显示不像Zend Framework 2编码惯例.请给我一个简单的方法来自动格式化代码遵循 Eclipse 4.4 Luna PDT( PHP开发工具)中的Zend Framework编码约定.

解决方法

我曾经使用Eclipse和PDT一段时间.然后我切换到另一个IDE.无论如何,在Eclipse中,您可以编辑autoformat的工作方式.您可以在窗口中编辑Autoformat – >首选项然后在PHP下 – >代码风格.对我来说,它从一开始就与Zend Framework 2一起运作良好.

在那里,您还可以找到导出/导入设置的可能性.我刚出口我的.
您可以将以下代码保存为.xml,然后将其导入到您能够编辑设置的相同位置.希望这可能会对你有所帮助.

不要忘记,首先要备份你的,只是为了确定. (我使用Eclipse 4.2.2& PDT 3.1.1)

代码模板的XML

<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="true" context="php_gettercomment_context" deleted="false" description="Comment for getter methods" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.gettercomment" name="gettercomment">/**
 * @return the ${bare_field_name}
 */</template><template autoinsert="true" context="php_settercomment_context" deleted="false" description="Comment for setter methods" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.settercomment" name="settercomment">/**
 * @param ${field_type} ${bare_field_name}
 */</template><template autoinsert="true" context="php_constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.constructorcomment" name="constructorcomment">/**
 * ${tags}
 */</template><template autoinsert="true" context="php_filecomment_context" deleted="false" description="Comment for created PHP files" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.filecomment" name="filecomment">/**
 * 
 */
</template><template autoinsert="true" context="php_typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.typecomment" name="typecomment">/**
 * @author ${user}
 *
 * ${tags}
 */</template><template autoinsert="true" context="php_fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.fieldcomment" name="fieldcomment">/**
 * @var ${field_type}
 */</template><template autoinsert="true" context="php_methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.methodcomment" name="methodcomment">/**
 * ${tags}
 */</template><template autoinsert="true" context="php_overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.overridecomment" name="overridecomment">/* (non-PHPdoc)
 * ${see_to_overridden}
 */</template><template autoinsert="true" context="php_delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.delegatecomment" name="delegatecomment">/**
 * ${tags}
 * ${see_to_target}
 */</template><template autoinsert="true" context="php_newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.newtype" name="newtype">${filecomment}
${package_declaration}

${typecomment}
${type_declaration}</template><template autoinsert="false" context="php_classbody_context" deleted="false" description="Code in new class type bodies" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.classbody" name="classbody">
</template><template autoinsert="false" context="php_interfacebody_context" deleted="false" description="Code in new interface type bodies" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.interfacebody" name="interfacebody">
</template><template autoinsert="true" context="php_catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.catchblock" name="catchblock">// ${TODO} Auto-generated catch block
${exception_var}.printStackTrace();</template><template autoinsert="true" context="php_methodbody_context" deleted="false" description="Code in created method stubs" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.methodbody" name="methodbody">// ${TODO} Auto-generated method stub
${body_statement}</template><template autoinsert="true" context="php_constructorbody_context" deleted="false" description="Code in created constructor stubs" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.constructorbody" name="constructorbody">${body_statement}
// ${TODO} Auto-generated constructor stub</template><template autoinsert="true" context="php_getterbody_context" deleted="false" description="Code in created getters" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.getterbody" name="getterbody">return ${field};</template><template autoinsert="true" context="php_setterbody_context" deleted="false" description="Code in created setters" enabled="true" id="org.eclipse.php.ui.editor.templates.php.codetemplates.setterbody" name="setterbody">${field} = ${param};</template><template autoinsert="true" context="php_new_file_context" deleted="false" description="Simple php file" enabled="true" id="org.eclipse.php.ui.editor.templates.php.author" name="New simple PHP file">&lt;?php
${cursor}</template><template autoinsert="true" context="php_new_file_context" deleted="false" description="html 4.01 frameset" enabled="true" id="org.eclipse.php.ui.editor.templates.php.html.frameset" name="New PHP file - HTML frameset">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=${encoding}"&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;/head&gt;
&lt;frameset&gt;
    &lt;frame&gt;
    &lt;frame&gt;
    &lt;noframes&gt;
    &lt;body&gt;
    &lt;p&gt;This page uses frames. The current browser you are using does not support frames.&lt;/p&gt;
    &lt;?php
${cursor}
    ?&gt;
    &lt;/body&gt;
    &lt;/noframes&gt;
&lt;/frameset&gt;
&lt;/html&gt;</template></templates>

格式化程序设置

来自menupoint Formatters的设置(在代码模板下面)在我的Eclipse中设置如下:

标签策略:标签

缩进尺寸:1

标签尺寸:4

包装线的默认indentatino:1

数组初始值设定项的默认缩进:1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读