PhpStorm 利用实时模板实现常用代码的快速编写

在日常的代码编写中,我们经常会用到例如try/catch,fori循环等,我们可以将这些代码添加到phpstorm的实时模板中,实现用几个字母快速生成代码,

1=> 点击左上角的file→settings

2=> editor→live templates→选择所编写的代码语言,以PHP为例→点击右侧 + →live templates

3=>分别填写 代码缩写,代码描述和代码内容;以fori循环为例

 4=>点击define 选择实时模板生效的环境;这里我们选择PHP

 5=>最后点击Apply ,OK;此时一个fori循环的实时模板就添加完成了

 之后我们在代码中只要输入fori就能快速关联出对应的代码了

 在这里推荐几个常用的实时模板

tryc=>try/catch

try {
    $req = $this->request->post();
   
    $this->success('请求成功');
} catch (Exception $e) {
    $this->error($e->getMessage());
}

ifstrpos=>字符串包含 

if(strpos('abcde','abc') !== false){ 
 echo '包含abc'; 
}else{
 echo '不包含abc'; 
}

猜你喜欢

转载自blog.csdn.net/echozly/article/details/122256363
今日推荐