为了账号安全,请及时绑定邮箱和手机立即绑定

快速入门ThinkPHP 5.0--基础篇

难度中级
时长 5小时20分
学习人数
综合评分9.63
150人评价 查看评价
9.8 内容实用
9.6 简洁易懂
9.5 逻辑清晰
  • tp\thinkphp\Request.php文件有所以的请求方法 //获取当前是哪个模块\控制器\操作 再操作,用于调试 dump($request->module()); dump($request->controller()); dump($request->action()); dump($request->url());//当前.URL ./index/Index/index/type/5.html?id=10 dump($request->baseUrl());//不用?号后的参数
    查看全部
  • //获取域名\路由\地址 use think\Request public function index(Request $request){ dump($request->domain());//http://jianpf.com dump($request->pathinfo());//index/index/index.html dump($request->path());//index/index/index //请求类型 dump($request->method());//GET请求 dump($request->isGet());//GET请求true dump($request->isPost());//POST请求true dump($request->isAjax());//AJAX请求true //获取请求的参数 dump($request->get());//tp5开始get数组没有了pathinfo等信息,只有参数的数组 dump($request->param());//方法名也放数组中 dump($request->post()); //使用session需要开启session //tp\thinkphp\convent.php下的第198行session=>['auto_start'=>ture]和删除session安全'httpponly'和'secure'配置 dump($request->session());//session('name','jianpf');session助手函数 dump($request->cookie());//cookie('email','372191242@qq.com');cookie助手函数 dump($request-param('name'));//获取单个值 dump($request->session('name'));//获取单个值 dump($request->cookie('name'));//获取单个值
    查看全部
  • tp\public\index.php tp\thinkphp\start.php tp\thinkphp\base.php namespace thinkphp;\\对应于tp\thinkphp\library App::run()->send();\\对应于tp\thinkphp\library\App.php //run()方法只执行一次 /** * 执行应用程序 * @access public * @param Request $request Request对象 * @return Response * @throws Exception */ public static function run(Request $request = null) { is_null($request) && $request = Request::instance(); try { $config = self::initCommon(); if (defined('BIND_MODULE')) { // 模块/控制器绑定 BIND_MODULE && Route::bind(BIND_MODULE); } elseif ($config['auto_bind_module']) { // 入口自动绑定 $name = pathinfo($request->baseFile(), PATHINFO_FILENAME); if ($name && 'index' != $name && is_dir(APP_PATH . $name)) { Route::bind($name); } }
    查看全部
  • tp请求对象获取 request()老忘记request和response //方法注入请求 public function index(Request $requests){dump($request)} 助手函数request();//返回的是个对象 使用use think\Request; $res=Request::instance();//放回的是哥对象
    查看全部
    0 采集 收起 来源:请求对象获取

    2017-05-31

  • tp\application\index\controller\Index.php下添加方法 public function info($id){return "{$id}"} tp\application\conf\route.php文件定义路由 <? return ['news/:id'=>'index/index/info'] //tp\thinkphp\convention.php文件是否开启路由 'url_routeion'=>true,//85行 'url_route_must'=>false//强制使用路由(静态路由,必须有路由,否则报错找不到) //启用路由可以用url()函数返回路由URL地址 echo url('index/index/index',['id'=>10]).'<br/>' 输出/index/Index/index/id/10 echo url('index/index/info',['id'=>10]).'<br/>' 输出/news/10.html
    查看全部
    1 采集 收起 来源:路由

    2018-03-22

  • tp\public\index.php入口文件指定默认模块 define('BIND_MODULE','admin');//绑定admin模块 define('BIND_MODULE','admin\index');//绑定admin模块index.php文件(只能传递方法),URL:localhost\User\index会报错admin\index.php中没有User->index方法 //给网站添加API tp\public\api.php内容: <?php define("APP_PATH",__DIR__.'/../app/'); define("CONF_PATH",__DIR__.'/../conf/'); define("BIND_MODULE",'api');//tp\application\api\controller\index.php require(__DIR__.'/../thinkphp/stat.php'); tp\thinkphp\convention.php惯例配置的auto_bind_module=>true 就可以不用在入口文件define("BIND_MODULE",'api');//直接按照http://localhost/api.php的文件绑定模块,不能访问其他模块
    查看全部
  • MAMP启用Apache的隐藏入口文件URL重写规则 \mamp\config\apache\httpd.conf文件 第130行 rewrite_module 打开LoadModule rewrite_module modules/mod_rewrite.so 第239行 网站的目录地址下 AllowOverride None 改成 AllowOverride All 重启MAMP服务器 URL重写规则启用tp\public\.htaccess文件重写的,没有就报错Not Found
    查看全部
    0 采集 收起 来源:隐藏入口文件

    2017-05-31

  • tp5的但入口文件,大厦的入口,由宝安指路 tp\public\index.php tp\application应用目录 tp\conf全局配置目录 tp\extend全局拓展配置目录 tp\thinkphp\base.php基本配置文件 tp\thinkphp\start.php安全过滤
    查看全部
    0 采集 收起 来源:隐藏入口文件

    2017-05-31

  • dump(\think\Env::get('status'));//获取单个.env变量 tp\.env内容 status=dev//环境变量识别场景配置 (线上线下开发) //判断开发环境 $res=Env::get('status','prod');//PHP_STATUS=prod标记 tp/application/conf/config.php内容: <?php //导入Env类(这里是重点...) use think\Env; return ['app_status'=>Env::get('app_status','dev')];//没有就读tp/application/conf/dev.php配置文件 dump(config());
    查看全部
  • //Env系统函数 use think\Env; $res=Env::get('email');//下标小写 $res=Env::get('email不存在');//返回NULL值 $res=Env::get('email不存在','直接返回此值'); //Env支持点语法 $res=Env::get('database_hostname'); $res=Env::get('database.hostname'); //打印系统环境变量 dump($_ENY); //自定义系统环境变量 tp/.env内容 email=372191242@qq.com database_hostname=localhost database_username=root database_password=root #分组等效 [database] hostname=localhost username=root password=root dump($_ENV['PHP_EMAIL'])//下标变大写 //只输出['PHP_EMAIL']=>string(15)
    查看全部
  • //实例化当前所给位置下的Yndex.php对象$a $a=new Yndex(); //调用Yndex.php对象的方法jpf(); return $a->jpf();
    查看全部
  • tp的::双冒号是静态方法 $res=Config::has('app_debug');//tp/thinkphp/convention.php惯例配置文件 tp\thinkphp\library\think\config.php /** * 检测配置是否存在 * @param string $name 配置参数名(支持二级配置 .号分割) * @param string $range 作用域 * @return bool */ public static function has($name, $range = '') { $range = $range ?: self::$range; if (!strpos($name, '.')) { return isset(self::$config[$range][strtolower($name)]); } else { // 二维数组设置和获取支持 $name = explode('.', $name, 2); return isset(self::$config[$range][strtolower($name[0])][$name[1]]); } }
    查看全部
  • tp\thinkphp\helper.php助手函数初始化文件 /** 判断助手函数是否不存在用户函数 */ if (!function_exists('config')) { /** * 获取和设置配置参数 * @param string|array $name 参数名 * @param mixed $value 参数值 * @param string $range 作用域 * @return mixed */ function config($name = '', $value = null, $range = '') { if (is_null($value) && is_string($name)) { return 0 === strpos($name, '?') ? Config::has(substr($name, 1), $range) : Config::get($name, $range); } else { return Config::set($name, $value, $range); } } } //注意::Config是首字母大写 Config::get('配置名'); config('配置名','配置值','配置作用域标记是否一样'); config('?配置名值是否不为null');
    查看全部
  • config类和config助手函数 tp\thinkphp\library\think\Config.php文件 range()方法:设置配置参数的作用域 parse()方法:解析配置文件或内容 load()方法:加载配置文件(PHP格式) has()方法:检测配置是否存在 get()方法:获取 set()方法:设置 reset()方法:重置配置 1.加载助手类,并使用框架助手函数 use think\Config; $res=Config::get(); 2.全路径指向类,并使用框架助手函数 $res=\think\Config::get(); 3.助手函数(不一定是框架助手类)$res=config(); dump($res);
    查看全部
  • 动态配置config()函数 //01魔术方法:类自动加载方法 public function __construct(){config('before','beforeAction');//动态配置} //修改配置(简单连接MYSQL数据库) \think\Config::set('database.type','mysql');//连接MYSQL \think\Config::set('database.database','test');//数据库名 \think\Config::set('database.username','root');//MYSQL用户 \think\Config::set('database.prefix','');//表前缀 $data = ['字段1' => '值1', '字段2' => '值2']; $res=\think\Db::table('表名')->insert($data);//插入数据 dump($res); $res=\think\Db::table('表名')->select();//查询数据 dump($res);
    查看全部
    0 采集 收起 来源:动态配置

    2018-03-22

举报

0/150
提交
取消
课程须知
1、有一定的php基础。 2、对git composer 有一定的了解。 3、本机安装好相应的开发环境 4、最好有一定的mvc 框架的使用经验
老师告诉你能学到什么?
1、框架的搭建 2、目录文件的介绍 3、环境的配置 (开发 测试 线上环境) 4、请求对象和数据请求参数获取 5、相应对象和返回相应类型的数据 6、模板的使用 比较 判断 循环

微信扫码,参与3人拼团

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!