? laravel composer create-project laravel/laravel test --prefer-distInstalling laravel/laravel (v4.2.0) - Installing laravel/laravel (v4.2.0) Downloading: 100%Created project in testLoading composer repositories with package informationInstalling dependencies (including require-dev) - Installing symfony/translation (v2.5.4) Downloading: 100% - Installing psr/log (1.0.0) Downloading: 100% - Installing symfony/security-core (v2.5.4) Downloading: 100% - Installing symfony/debug (v2.5.4) Downloading: 100% - Installing symfony/http-foundation (v2.5.4) Downloading: 100% - Installing symfony/event-dispatcher (v2.5.4) Downloading: 100% - Installing symfony/http-kernel (v2.5.4) Downloading: 100% - Installing symfony/routing (v2.5.4) Downloading: 100% - Installing symfony/process (v2.5.4) Downloading: 100% - Installing symfony/finder (v2.5.4) Downloading: 100% - Installing symfony/console (v2.5.4) Downloading: 100% - Installing symfony/filesystem (v2.5.4) Downloading: 100% - Installing symfony/dom-crawler (v2.5.4) Downloading: 100% - Installing symfony/css-selector (v2.5.4) Downloading: 100% - Installing symfony/browser-kit (v2.5.4) Downloading: 100% - Installing swiftmailer/swiftmailer (v5.2.2) Downloading: 100% - Installing stack/builder (v1.0.2) Downloading: 100% - Installing predis/predis (v0.8.7) Downloading: 100% - Installing phpseclib/phpseclib (0.3.8) Downloading: 100% - Installing patchwork/utf8 (v1.1.25) Downloading: 100% - Installing nesbot/carbon (1.13.0) Downloading: 100% - Installing monolog/monolog (1.10.0) Downloading: 100% - Installing nikic/php-parser (v0.9.5) Downloading: 100% - Installing jeremeamia/superclosure (1.0.1) Downloading: 100% - Installing ircmaxell/password-compat (1.0.3) Downloading: 100% - Installing d11wtq/boris (v1.0.8) Downloading: 100% - Installing html' target='_blank'>classpreloader/classpreloader (1.0.2) Downloading: 100% - Installing filp/whoops (1.1.2) Downloading: 100% - Installing laravel/framework (v4.2.9) Downloading: 100%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.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 fileGenerating autoload filesMcrypt PHP extension required.Script php artisan clear-compiled handling the post-install-cmd event returned with an error一共有28个需要Install的,这个导致的结果是初始化可运行的项目大小有25M之大。 这么bigger than bigger的玩意,首先会带来部署上的不便利。 部署laravel项目的时候会有两种方式,一种是只发布除了vendor之外的项目相关的文件,然后运行composer进行vender的更新,另外一种是直接将vendor进入版本库,使用版本库的发布将所有代码发布到线上机器去。我个人倾向第二种,能把代码库中的文件直接放到服务器上就能运行的多牛逼。但是这样子,代码库就变得超大了,不大便利了。 其次,这么多的vendor导致的是文档查阅的不方便。 一个框架好用不好用,文档是一个至关重要的环节。但是引用的第三方库一多了,很多使用文档官方就没有足够详细的文档说明了,然后美其名告诉你,这个是引用第三方库的,给你个链接,你去第三方库的说明文档中看把。但是你要知道,在开发过程中,文档是需要有统一性的,每一个说明文档的展示和查询规则都是有惯性的。你给个链接让我去一个不一样布局的网页,我的思维还需要进行跳跃和查找。解决办法:忍吐槽点:laravel的路由可以写functionlaravel的路由非常强大,强大到无敌了。比如说呢,什么controller,action啥的都是浮云,哥可以在app/route.php里面直接写上路由对应的funciton,啥controller都不用写了,一个文件可以do everything。但是,什么都能做的框架就是把规则的制定推给使用者。比如在route中可以允许写function,我第一次看到的时候觉得浑身都不对了,一个制定路由的文件,你就制定哪个路由到哪个action就好,干毛在一个叫route.php的文件里面,制定具体的执行方法。我估摸很多团队都会约定不允许在route里面写funciton,因为这样就个路由的设置就很鸡肋了。解决办法:团队自行做一些规定来限制路由的功能。吐槽点:laravel没有默认路由我这里说的是比如yii中有默认路由的方式controller/action。比如user/index 默认就对应到userController 的IndexAction中去。但是在laravel中,它将这种名称依赖的默认路由去掉了。所有laravel中使用的路由都需要手动在route.php中制定诸如这样的命令:
Route::get('login', ['as' => 'login', 'uses' => 'UserController@login']);但是特别在做后台开发的时候真是特别无法忍受,每次增加一个路由都需要在route中加入这么一条玩意。 最后我取折衷的办法,在后台开发的时候,多使用这样的语句:
Route::controller('series', 'SeriesController’);这样,在controller中定义的getXXX和postXXX就能自动解析了,就不需要那么繁杂的写route路径了。解决办法:多使用Route::controller吐槽点:日志记录信息太多了看看默认的laravel.log中的一个错误:
<?phpnamespace YejiafnengHelpers; use MonologLogger;use MonologHandlerStreamHandler;use IlluminateLogWriter; 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 = 30) { 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);});这里没有修改laravel自身的错误日志记录,因为保留一个全集的错误应该还是有必要的,但是实际上我使用过程中只要看自己定义的error.log就足够了
Student::where('female', 1)->where('teacher_id', 4)->where('class_id', 3)->get();好难受,如果一个还行,要是多个呢?。。。难道就不能在一个where中使用个数组么?解决办法:在基类中扩展一个multiwhere于是我就在BaseModel中定义了:
// 多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’=>1, ’teacher_id’ => 4, ‘class_id’ => 3])->get();
一下子腰也不酸了,头也不疼了。。。
后记laravel还是能让一个phper学习到很多的,我努力着爱之深责之切的原则,后续使用laravel中使用不爽的地方再继续吐槽和讨论。
PHP编程郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答