composer autoload対応の素晴らしさを前回の記事で書いたけど、最小限の例を用意していないので、ちょっと書いてみる。
composer autoloadを使うと、requireを書く必要が(ほぼ)無くなるよ。
composerがインストールされている前提で、まず、プロジェクトルートにcomposer.jsonファイルを作成する。
$results = \DB::select('select * from articles where id = ?', [2]);Query Builderの説明を読んだほうが早い。通常はEloquent使うと思うので使わないと思う。特殊なSQLを発行したい時に使おう。
use Illuminate\Database\Eloquent\Model;
class User extends Model| まあそんなことしないと思いますが… | |
| ちなみにこれはlaravelの機能ではなく、phpdotenvというライブラリです。他言語のもあります。 |
ほっといたら例外はログに出るんだけど、例えばログには吐きたいけどcatchしてプログラムを終了させたくない時は、
try {
} catch(FooException $e) {
\App::make('Illuminate\Contracts\Debug\ExceptionHandler')->report($e);
// ...
}インストール方法はREADME.mdに大体書いてあるけど、何となく使ってみたくなったもので…
| services: | |
| twig.extension.text: | |
| class: Twig_Extensions_Extension_Text | |
| tags: | |
| - { name: twig.extension } |
| // | |
| // RootViewController.m | |
| // Locations | |
| // | |
| // Created by nazo on 12/05/31. | |
| // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. | |
| // | |
| #import "RootViewController.h" |
| def read() | |
| files = {} | |
| while line = STDIN.gets | |
| if /^([^:]*):([0-9]+):([0-9]+): *(.*)$/ =~ line | |
| filename, line, column, message = $1, $2, $3, $4 | |
| if !files.has_key?(filename) | |
| files[filename] = [] | |
| end | |
| files[filename].push({:line => line, :column => column, :message => message}) | |
| end |