前言:我的杂项php
2018.5.17 14:55html
1. lumne 链接Sqlite时,一直报错: Call to a member function connection() on nulllaravel
解决方法:sql
app.php中打开Orm的注释!!!坑爹,谁关了!!!segmentfault
17:03数组
2. lumen、laravel配置打印sqlapp
https://blog.csdn.net/zy994914376/article/details/54891068框架
当前,本身配置的是lumen。与laravle 不一样的是lumen没有make listener的命令,因此有些包须要本身导入。ide
2018.6.1 16:58函数
1. laravel源码学习,自动加载的疑惑。关于spl_autoload_register()
https://segmentfault.com/q/1010000012093950
ps:spl_autoload_register()函数中队列已经存在的方法,若是不unregister的话,是一直存在的!以前,个人认知是觉得只能使用一次,这个是错误的。
2018.6.4 11:15
1. laravel源码学习,new static的疑惑(门面的代码部分)
延迟动态绑定,以前我是了解过的。可是有点不明白的是,在源码中为何要new static,估计是给其余部分继承的、
后续,本身看了下有关的知识,更深层次了解了下new static 与new self 的区别。
参考:https://blog.csdn.net/qq_25600055/article/details/78549435
本身另外一篇讲解:
http://www.cnblogs.com/mikusnail/p/9132520.html
2. trait 的总结:
1) 优先级:当前类的方法会覆盖trait中的方法,而trait中的方法会覆盖基类的方法
2 ) 多个trait组合:经过逗号分隔,经过use关键字列出多个trait
3) 冲突的解决:若是两个trait都插入了一个同名的方法,若没明确解决冲突将会产生一个致命的错误。为了解决多个trait在同一个类中的命名冲突,须要使用insteadof操做符来明确指定使用冲突方法中的哪个。
同时,能够经过as操做符将其中一个冲突的方法以另外一个名称来引入
4) 修改方法的访问控制:使用as语法能够用来调整方法的访问控制
5) trait的抽象方法:在trait中可使用抽象成员,使得类中 必须实现这个抽象方法
6) trait的静态成员:在trait中能够用静态方法和静态变量
7) trait的属性定义:在trait中一样能够定义属性
2018.6.7 13:26
1. laravel 的路由namesapce是从 App\Http\Controllers开始的,因此只要从这部分后面开始指定便可。
2018.6.13 15:29
1. laravel 中的请求处理管道(其实,大白话是一个请求进入框架中的生命周期)使用的是装饰者模式
简易理解版本的demo():
1 interface Step { 2 public static function go(Closure $next); 3 } 4 5 class FirstStep implements Step { 6 public static function go(Closure $next) { 7 echo 'start' . '<br />'; 8 $next(); 9 echo 'end' . '<br />'; 10 } 11 } 12 13 function goFun($step,$className) { 14 return function() use($step,$className) { 15 return $className::go($step); 16 }; 17 } 18 19 function then() { 20 $steps = ["FirstStep"]; 21 $prepare = function(){ 22 echo 'prepare' . '<br />'; 23 }; 24 $go = array_reduce($steps,"goFun",$prepare); //此处能够精简为: call_user_func(); 25 $go(); 26 } 27 28 then();
执行结果:
start
prepare
end
ps:
其实,laravel内部维护了一个请求须要通过哪些步骤类的数组,经过顺序加载来达到前、后中间件的效果。
2018.6.14 15:55
1. Laravel 中获取文件的.env文件行数的代码:
$autodetect = ini_get('auto_detect_line_endings'); ini_set('auto_detect_line_endings', '1'); $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); ini_set('auto_detect_line_endings', $autodetect); return $lines;
ps:
1. auto_detect_line_endings的设置(这个,我真的是不看文档真的不知道,可见author是老司机啊~)
若是碰到 PHP 在读取文件时不能识别 Macintosh 文件的行结束符,能够激活 auto_detect_line_endings 运行时配置选项。
2. file函数的第二个参数,w3c上只是一个include_path,其实否则。(可见,平时仍是用手册吧)
2. :todo
https://www.jianshu.com/p/ee92b36e2839
2018.6.22 10:35
1. 关于laravel路由执行的代码,目前还没有深究,先作个记录
2018.6.28 16:00
1. 执行迁移 php artisan migrate
1071 Specified key was too long; max key length is 1000 bytes
解决方法:
升级MySql版本到5.5.3以上。(以前我本身升级过,貌似不行。。。可能姿式不对?)
手动配置迁移命令migrate
生成的默认字符串长度,在AppServiceProvider
中调用Schema::defaultStringLength
方法来实现配置:
添加,use Illuminate\Support\Facades\Schema;
boot方法中添加,Schema::defaultStringLength(191);
2018.6.29 14:02
1. laravel自定义包开发
https://blog.csdn.net/juner_ge/article/details/51766830