vscode 代码片段 php.json

1.设置-》用户代码片段-》新建全局代码片段文件-》php.json

 

复制代码
{
    // Place your snippets for php here. Each snippet is defined under a snippet name and has a prefix, body and
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
    // same ids are connected.
    // Example:
    // "Print to console": {
    //  "prefix": "log",
    //  "body": [
    //      "console.log('$1');",
    //      "$2"
    //  ],
    //  "description": "Log output to console"
    // }
    "public": {
        "prefix": "public",
        "body": [
       
            "public function $1($2):$3",
            "{",
            "    $4",
            "}"
        ],
        "description": "Log output to console"
    },
    "protected": {
        "prefix": "protected",
        "body": [
       
            "protected function $1($2):$3",
            "{",
            "    $4",
            "}"
        ],
        "description": "Log output to console"
    },
    "private": {
        "prefix": "private",
        "body": [
       
            "private function $1($2):$3",
            "{",
            "    $4",
            "}"
        ],
        "description": "Log output to console"
    },
    "static": {
        "prefix": "static",
        "body": [
       
            "public static function $1($2):$3",
            "{",
            "    $4",
            "}"
        ],
        "description": "Log output to console"
    },
    "foreach": {
        "prefix": "foreach",
        "body": [
            "foreach($1 as \\$key=>\\$item){",
            "    $2",
            "}"
        ],
        "description": "Log output to console"
    },
    "if": {
        "prefix": "if",
        "body": [
            "if($1){",
            "    $2",
            "}"
        ],
        "description": "Log output to console"
    },
    "startTrans": {
        "prefix": "startTrans",
        "body": [
            "Db::startTrans();",
            "try {",
            "    $1",
            "    // 提交事务",
            "    Db::commit();",
            "} catch (\\Exception \\$e) {",
            "    // 回滚事务",
            "    Db::rollback();",
            "    throwError(\\$e->getMessage());",
            "}",
            "return true;",
        ],
        "description": "Log output to console"
    },
    "transaction": {
        "prefix": "transaction",
        "body": [
            "transaction(function () use ($1) {",
            "    $2",
            "});",
        ],
        "description": "Log output to console"
    },
}
复制代码

2.在设置中搜索到editor.snippetSuggestions这个设置,其中有四个选项top、bottom、inline、none四个选项,选择top即可
作用:使用户自定义的代码片段在提示的最上面

 

posted @   会飞的鹏  阅读(87)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2016-01-02 checkbox属性checked="checked"通过js已设置,但是不勾选
点击右上角即可分享
微信分享提示