API itzulpenaren erabiltzailearen eskuliburua

ilustratu: erabiliDb::return_json_exit() Metodoa erabiltzean, itzuli beharreko eremuaren bidea zehaztu dezakezu bigarren parametroaren bidez.

Oinarrizko erabilera

1. Itzuli eremu espezifikoak

Itzuli `prezio_planak` ataleko txinerazko testu guztia eta `mezua` balioa:

Db::return_json_exit([
    'code' => 200,
    'message' => '成功',
    'data' => [
        'pricing_plans' => [
            'basic' => [
                'name' => '基础套餐',
                'price' => 99,
                'features' => ['功能一', '功能二']
            ],
            'pro' => [
                'name' => '专业套餐',
                'price' => 299,
                'features' => ['高级功能', '优先支持']
            ]
        ],
        'user' => [
            'name' => '张三',
            'profile' => [
                'city' => '北京',
                'bio' => '个人简介'
            ]
        ],
        'aaa' => '你好'
    ]
], ['data.pricing_plans.*', 'message']);

2. Zehaztutako bideak eta azpibideak itzuli

Itzuli txinatar karaktere guztiak eremu espezifikoen izenaren eta pro-aren azpian:

Db::return_json_exit([
    'code' => 200,
    'message' => '成功',
    'data' => [
        'pricing_plans' => [
            'basic' => [
                'name' => '基础套餐',
                'price' => 99,
                'features' => ['功能一', '功能二']
            ],
            'pro' => [
                'name' => '专业套餐',
                'price' => 299,
                'features' => ['高级功能', '优先支持']
            ]
        ],
        'user' => [
            'name' => '张三',
            'profile' => [
                'city' => '北京',
                'bio' => '个人简介'
            ]
        ],
        'aaa' => '你好'
    ]
], ['data.pricing_plans.basic.name', 'data.pricing_plans.pro.*']);

3. Datu-objektu osoa itzuli

Itzuli datu-karpetako eduki guztia karaktere komodinak erabiliz:

Db::return_json_exit([
    'code' => 200,
    'message' => '成功',
    'data' => [
        'pricing_plans' => [
            'basic' => [
                'name' => '基础套餐',
                'price' => 99,
                'features' => ['功能一', '功能二']
            ],
            'pro' => [
                'name' => '专业套餐',
                'price' => 299,
                'features' => ['高级功能', '优先支持']
            ]
        ],
        'user' => [
            'name' => '张三',
            'profile' => [
                'city' => '北京',
                'bio' => '个人简介'
            ]
        ],
        'aaa' => '你好'
    ]
], ['data.*']);

4. Ez itzuli (lehenetsia)

Bigarren parametroa ezabatzen da, eta ez da itzulpenik egiten:

Db::return_json_exit([
    'code' => 200,
    'message' => '成功',
    'data' => [
        'pricing_plans' => [
            'basic' => [
                'name' => '基础套餐',
                'price' => 99,
                'features' => ['功能一', '功能二']
            ],
            'pro' => [
                'name' => '专业套餐',
                'price' => 299,
                'features' => ['高级功能', '优先支持']
            ]
        ],
        'user' => [
            'name' => '张三',
            'profile' => [
                'city' => '北京',
                'bio' => '个人简介'
            ]
        ],
        'aaa' => '你好'
    ]
]);

Bidearen sintaxiaren deskribapena