➜ laravel composer create-project laravel/laravel test --prefer-dist Installing laravel/laravel (v4.2.0) - Installing laravel/laravel (v4.2.0) Downloading: 100% Created project in test Loading composer repositories with package information Installing 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 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 file Generating autoload files Mcrypt PHP extension required. Script php artisan clear-compiled handling the post-install-cmd event returned with an error
Route::get('login', ['as' => 'login', 'uses' => 'UserController@login']);
Route::controller('series', 'SeriesController’);
<?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 = 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); });
Student::where('female', 1) ->where('teacher_id', 4) ->where('class_id', 3) ->get();
// 多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中使用不爽的地方再继续吐槽和讨论。