PHP code example of xvv / think-jump

1. Go to this page and download the library: Download xvv/think-jump library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xvv / think-jump example snippets



namespace app\controller;

use xvv\think\Jump;

class Index extends BaseController
{
    use Jump;

    public function index()
    {
        // 操作成功,跳转到首页
        $this->success('登录成功', '/index/home');

        // 操作失败,返回上一页
        $this->error('用户名或密码错误');

        // AJAX 请求成功
        $this->success('保存成功', null, ['id' => 100]);

        // 直接重定向
        $this->redirect('/user/profile');

        // API 接口返回
        $this->result(['list' => []], 0, '查询成功');
    }
}


// config/jump.php
return [
    // 成功跳转页模板路径
    'dispatch_success_tpl' => app()->getRootPath() . '/vendor/xvv/think-jump/src/tpl/success.html',
    // 失败跳转页模板路径
    'dispatch_error_tpl'   => app()->getRootPath() . '/vendor/xvv/think-jump/src/tpl/error.html',

    // 成功响应 code 值
    'default_success_code' => 0,
    // 失败响应 code 值
    'default_error_code'   => 1,

    // 成功跳转等待秒数
    'default_success_wait' => 3,
    // 失败跳转等待秒数
    'default_error_wait'   => 3,

    // 默认输出类型(非 AJAX 请求)
    'default_return_type'  => 'html',
    // AJAX 请求默认返回格式,支持 json / jsonp / xml
    'default_ajax_return'  => 'json',
];

$this->success('更新成功', 'user/profile');  // 自动构建为 /user/profile
bash
php think service:discover
php think vendor:publish