当前位置: 首页 > 后端技术 > PHP

在YII2项目中,重写PhpStorm中方法函数的注释代码

时间:2023-03-30 02:54:27 PHP

1说明Yii2默认的可访问路由都是以action开头的,但是当项目多了,action的名字就变长了,而且每次都要转换大小写全局搜索action,非常不方便,所以我们重写了phpstorm一个函数注解的工具,这样我们在写action方法的时候,只需要输入/**然后回车就可以显示下面的代码,如下图,action自动拆分,这样我们可以愉快的搜索2操作步骤依次打开File->Settings->Editor->FileandCodeTemplates(或者使用快捷键ctrl+shift+s)在界面右侧找到Includes,点击PHPFunctionDocComment,然后把下面的代码复制进去,点击apply->ok3.配置代码/***@note:#if($NAME.length()>6)#set($formatAction='')#if($NAME.substring(0,6)=='action')#set($len=$NAME.length())#set($actionName=$NAME.substring(6,$len))#set($actionLen=${len}-6-1)#foreach($startin[0..$actionLen])#set($end=${start}+1)#set($tmpStr=$actionName.substring($start,$end))#如果($tmpStr.toUpperCase()==$tmpStr)#set($tmpLowerStr=$tmpStr.toLowerCase())#if($start!=0)#set($formatAction="${formatAction}-")#结束#放($formatAction="${formatAction}${tmpLowerStr}")#else#set($formatAction="${formatAction}${tmpStr}")#end#end*@action$formatAction#else*@func$NAME#end#else*@func$NAME#end${PARAM_DOC}#if(${TYPE_HINT}!="void")*@return${TYPE_HINT}#end${THROWS_DOC}*/4、相关网站http://velocity.apache.org/en...https://wizardforcel.gitbooks...