博客列表 >ThinkPHP5.1_创建控制器_2018年10月23日

ThinkPHP5.1_创建控制器_2018年10月23日

宋超的博客
宋超的博客原创
2018年10月28日 18:36:471930浏览

1.手动创建控制器实例

<?php
namespace app\index\controller;
use think\Controller;

class Demo3 extends Controller
{
    public function _empty($name)
    {
        return $this->show($name);
    }
    public function index()
    {
        return 123;
    }
    public function add()
    {
        return 'add';
    }
    
    public function edit($id)
    {
        return 'edit:'.$id;
    }

    public function jump()
    {
        return $this->success('ok','index');
    }
    public function show($name)
    {
        return '不存在操作'.$name;
    }

}

运行实例 »

点击 "运行实例" 按钮查看在线实例

2.使用命令行创建控制器 php think make:controller index/Demo4实例

<?php

namespace app\index\controller;

use think\Controller;
use think\Request;

class Demo4 extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return __METHOD__;
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        return __METHOD__;
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        return __METHOD__;
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        return __METHOD__.'_ID='.$id;
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议