laravel吐槽系列之一
吐槽点:laravel的vendor引用的组件过多
➜ laravel composer create-project laravel/laravel test --prefer-dist
Installing laravel/laravel (v4.2.0)
- Installing laravel/laravel (v4.2.0)
Downloading: % Created project in test
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing symfony/translation (v2.5.4)
Downloading: % - Installing psr/log (1.0.)
Downloading: % - Installing symfony/security-core (v2.5.4)
Downloading: % - Installing symfony/debug (v2.5.4)
Downloading: % - Installing symfony/http-foundation (v2.5.4)
Downloading: % - Installing symfony/event-dispatcher (v2.5.4)
Downloading: % - Installing symfony/http-kernel (v2.5.4)
Downloading: % - Installing symfony/routing (v2.5.4)
Downloading: % - Installing symfony/process (v2.5.4)
Downloading: % - Installing symfony/finder (v2.5.4)
Downloading: % - Installing symfony/console (v2.5.4)
Downloading: % - Installing symfony/filesystem (v2.5.4)
Downloading: % - Installing symfony/dom-crawler (v2.5.4)
Downloading: % - Installing symfony/css-selector (v2.5.4)
Downloading: % - Installing symfony/browser-kit (v2.5.4)
Downloading: % - Installing swiftmailer/swiftmailer (v5.2.2)
Downloading: % - Installing stack/builder (v1.0.2)
Downloading: % - Installing predis/predis (v0.8.7)
Downloading: % - Installing phpseclib/phpseclib (0.3.)
Downloading: % - Installing patchwork/utf8 (v1.1.25)
Downloading: % - Installing nesbot/carbon (1.13.)
Downloading: % - Installing monolog/monolog (1.10.)
Downloading: % - Installing nikic/php-parser (v0.9.5)
Downloading: % - Installing jeremeamia/superclosure (1.0.)
Downloading: % - Installing ircmaxell/password-compat (1.0.)
Downloading: % - Installing d11wtq/boris (v1.0.8)
Downloading: % - Installing classpreloader/classpreloader (1.0.)
Downloading: % - Installing filp/whoops (1.1.)
Downloading: % - Installing laravel/framework (v4.2.9)
Downloading: % symfony/translation suggests installing symfony/config ()
symfony/translation suggests installing symfony/yaml ()
symfony/security-core suggests installing symfony/validator (For using the user password constraint)
symfony/security-core suggests installing symfony/expression-language (For using the expression voter)
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/http-kernel suggests installing symfony/class-loader ()
symfony/http-kernel suggests installing symfony/config ()
symfony/http-kernel suggests installing symfony/dependency-injection ()
symfony/routing suggests installing symfony/config (For using the all-in-one router or any loader)
symfony/routing suggests installing symfony/yaml (For using the YAML loader)
symfony/routing suggests installing symfony/expression-language (For using expression matching)
symfony/routing suggests installing doctrine/annotations (For using the annotation loader)
predis/predis suggests installing ext-phpiredis (Allows faster serialization and deserialization of the Redis protocol)
phpseclib/phpseclib suggests installing ext-mcrypt (Install the Mcrypt extension in order to speed up a wide variety of cryptographic operations.)
phpseclib/phpseclib suggests installing ext-gmp (Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.)
phpseclib/phpseclib suggests installing pear-pear/PHP_Compat (Install PHP_Compat to get phpseclib working on PHP < 4.3..)
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
laravel/framework suggests installing doctrine/dbal (Allow renaming columns and dropping SQLite columns.)
Writing lock file
Generating autoload files
Mcrypt PHP extension required.
Script php artisan clear-compiled handling the post-install-cmd event returned with an error
解决办法:忍
吐槽点:laravel的路由可以写function
解决办法:团队自行做一些规定来限制路由的功能。
吐槽点:laravel没有默认路由
Route::get('login', ['as' => 'login', 'uses' => 'UserController@login']);
Route::controller('series', 'SeriesController’);
解决办法:多使用Route::controller
吐槽点:日志记录信息太多了

解决方法:自定义日志编辑类
<?php
namespace Yejiafneng\Helpers; use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Illuminate\Log\Writer; class BLogger
{
// 所有的LOG都要求在这里注册
const LOG_ERROR = 'error';
const LOG_SHOP = 'shop';
const LOG_QUERY = 'query';
const LOG_LOGIN = 'login'; private static $loggers = array(); // 获取一个实例
public static function getLogger($type = self::LOG_ERROR, $day = )
{
if (empty(self::$loggers[$type])) {
self::$loggers[$type] = new Writer(new Logger($type));
}
$log = self::$loggers[$type];
$log->useDailyFiles(storage_path().'/logs/'. $type .'.log', $day);
return $log;
}
}
然后在app/start/global.php中修改错误日志回调函数为:
// 错误日志信息
App::error(function(Exception $exception, $code)
{
// 如果没有路径就直接跳转到登录页面
if ($exception instanceof NotFoundHttpException) {
return Redirect::route('login');
} Log::error($exception); $err = [
'message' => $exception->getMessage(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'code' => $exception->getCode(),
'url' => Request::url(),
'input' => Input::all(),
];
BLogger::getLogger(BLogger::LOG_ERROR)->error($err);
});

吐槽点:ORM的where太弱
Student::where('female', )
->where('teacher_id', )
->where('class_id', )
->get();
解决办法:在基类中扩展一个multiwhere
// 多where
public function scopeMultiwhere($query, $arr)
{
if (!is_array($arr)) {
return $query;
} foreach ($arr as $key => $value) {
$query = $query->where($key, $value);
}
return $query;
}
Student::multiwhere([‘female’=>, ’teacher_id’ => , ‘class_id’ => ])->get();
一下子腰也不酸了,头也不疼了。。。
后记
laravel还是能让一个phper学习到很多的,我努力着爱之深责之切的原则,后续使用laravel中使用不爽的地方再继续吐槽和讨论。
laravel吐槽系列之一的更多相关文章
- Laravel 5 系列入门教程(一)【最适合中国人的 Laravel 教程】
Laravel 5 系列入门教程(一)[最适合中国人的 Laravel 教程] 分享⋅ johnlui⋅ 于 2年前 ⋅ 最后回复由 skys215于 11个月前 ⋅ 17543 阅读 原文发表在 ...
- Laravel 4 系列入门教程(一)
默认条件 本文默认你已经有配置完善的PHP+MySQL运行环境,懂得PHP网站运行的基础知识.跟随本教程走完一遍,你将会得到一个基础的包含登录的简单blog系统,并将学会如何使用一些强大的Larave ...
- Laravel 5系列教程五:MVC的基本流程
免费视频教程地址https://laravist.com/series/laravel-5-basic 期间受到很多私事影响,终于还是要好好写写laravel的教程了. 上一篇我们说了数据库和Eloq ...
- Laravel 5系列教程六:表单 Forms
免费视频教程地址https://laravist.com/series/laravel-5-basic 在开始之前,我们把界面先美化一点点先: 首先到https://github.com/JellyB ...
- Laravel 5系列教程四:数据库和Eloquent
免费视频教程地址https://laravist.com/series/laravel-5-basic 上一篇写了一些Laravel Blade的基本用法和给视图传递变量的几种方式, 这一节我们来说说 ...
- Laravel 5系列教程二:路由,视图,控制器工作流程
免费视频教程地址https://laravist.com/series/laravel-5-basic 上一篇教程我们走了那么长的路,终于把Laravel安装好了,这一篇教程我们就要进入Laravel ...
- Laravel 5 系列教程三:视图变量传递和Blade
免费视频教程地址https://laravist.com/series/laravel-5-basic 上一篇我们简单地说了Router,Views和Controllers的工作流程,这一次我就按照上 ...
- laravel进阶系列--通过事件和事件监听实现服务解耦
简介 Laravel 事件提供了简单的观察着模式实现,允许你订阅和监听应用中的事件.事件类通常存放在 app/Events 目录. 监听器存放在 app/Listeners. 如果你在应用中没有看到这 ...
- techiediaries网站的Laravel 6系列教程
Laravel 6 Tutorial & New Features - Build a CRM [PART 1] Laravel 6 REST API CRUD Tutorial - Buil ...
随机推荐
- ZeroMQ研究与应用分析
1 ZeroMQ概述 ZeroMQ是一种基于消息队列的多线程网络库,其对套接字类型.连接处理.帧.甚至路由的底层细节进行抽象,提供跨越多种传输协议的套接字.ZeroMQ是网络通信中新的一层,介于应用 ...
- 用UWP实现一个和win10设置页面类似的布局
不知道有人注意过Win10中的设置页面的布局没?那个页面会根据不同的窗口宽度来调节显示的内容,甚至来后退按钮的操作在不同的宽度也是不同的,看图: 是不是有点cool呢,这篇文章,我们就来做一个类似的布 ...
- 《你必须知道的.NET》读书笔记:从Hello World认识IL
通用的语言基础是.NET运行的基础,当我们对程序运行的结果有异议的时候,如何透过本质看表面,需要我们从底层来入手探索,这时候,IL便是我们必须知道的基础. 一.IL基础概念 1.1 什么是IL? IL ...
- 好用的SQL TVP~~独家赠送[增-删-改-查]的例子
以前总是追求新东西,发现基础才是最重要的,今年主要的目标是精通SQL查询和SQL性能优化. 本系列主要是针对T-SQL的总结. [T-SQL基础]01.单表查询-几道sql查询题 [T-SQL基础] ...
- SWF READER 破解日志。
网上传闻swf reader是破解最厉害的神器,可以内存抓取+doSWF反编译.所以去官网下了一个: SWF_Reader_2.3 不出所料,demo版本没有反编译的功能.网上搜到一个哥们尝试了下: ...
- MVVM架构~Knockoutjs系列之js接收C#数据集合的方式
返回目录 在controller里将数据拿到,并且存储到ViewBag对象里,最后在View上显示出来,这是传统的MVC开发方式,事实上引入Knockoutjs以后,这种方式还是适合的,Knockou ...
- 移动h5开发资源整理
这2年来,移动h5开发逐渐成为一种主流,也不断趋向于成熟.硬件和浏览器的不断更新,曾经的浏览器兼容也不再是开发者的噩梦. 接触h5开发一年多,从最初的新手到现在,陆陆续续遇到过很多坑.这里把想到的一些 ...
- lua的table表处理 及注意事项
lua,一款很轻量级很nice很强大的脚本语言,做为lua中使用最为频繁的table表,在使用之时还是有颇多的好处与坑的: 下面是大牛 云风的一片关于lua table的blog,可使得对lua ta ...
- 用VC编译lua源码,生成lua语言的解释器和编译器
用VC编译lua源码,生成lua语言的解释器和编译器 1.去网址下载源码 http://www.lua.org/download.html 2.装一个VC++,我用的是VC6.0 3.接下来我们开始编 ...
- salesforce 零基础学习(二十九)Record Types简单介绍
在项目中我们可能会遇见这种情况,不同的Profile拥有不同的页面,页面中的PickList标签可能显示不同的值.这个时候,使用Record Types可以很便捷的搞定需求. Record Types ...