2011年12月8日木曜日

consoleコマンドリスト

$ php app/console listのコマンドで、コンソールのコマンドリストを見れます。 別にコンソール上で見ればいいけど、一応一覧をメモっておく。 Symfony version 2.0.6 - app/dev/debug Usage:   [options] command [arguments] Options:   --help           -h Display this help message.   --quiet          -q Do not output any message.   --verbose        -v Increase verbosity of messages.   --version        -V Display this program version.   --ansi      ...

既存のテーブルからEntityを作成!

タイトルのように、既存のテーブルからEntityを作成したい場合は、どうするのかなーと思ってた所、こんな記事がありました。→ How to generate Entities from an Existing Datab...

2011年12月6日火曜日

controllerに書くアノテーションについて

SensioFrameworkExtraBundle Symfony2 では、アノテーションとして Routing の情報等を書くけど、そのアノテーションに関する情報がまとまってなくて、どっかにないかなーと思っていたら、ドキュメントにあったので、紹介 + 自分なりにまとめてみます。 とりあえず、アノテーションに以下の5つの機能があるっぽい @Route and @Method : ルーティングの情報や、ルートに許可されるHTTPメソッドを指定 @ParamConverter : リクエストの内容をオブジェクトに変換する機能を使用することを指定 @Template : テンプレート名を指定する @Cache : HTTPキャッシュを作成するためのアノテーション @Route and @Methodドキュメントはコチラ → @Route and @Method /**  * @Route("/{id}", requirements={"id" = "\d+"}, defaults={"foo" = "bar"})  */ public function showAction($id) { } @Route() では、第一引数で pattern 情報を指定 requirements...

アノテーションを使用するときはインポートすること!

@Route や @Template のアノテーションを利用するときは、 // these import the "@Route" and "@Template" annotations use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; のように、FrameworkExtraBundle の Configuration\Route と Configuration\Template をインポートするこ...

2011年12月5日月曜日

Actionの戻り値について

Symfony2.0 では、Controller の Action の戻り値は、Response オブジェクト。 ってのはまぁ、良いとして、Response オブジェクトの作成方法についてちょっと自分なりにメモしておく。 (間違ってたらコメントください(´・ω・`)) 基本的に以下の3パターン。 ( http://symfony.com/doc/current/book/controller.htmlより引用 ) ① 自分でレスポンスオブジェクトを作成 use Symfony\Component\HttpFoundation\Response; public function helloAction() {     return new Response('Hello world!'); } リダイレクトする場合は、このパターン ②render関数を Action 内で使用 自分でテンプレートを指定して、レンダリングを行う。render() の戻り値が Response オブジェクトなので、これをそのまま Action の戻り値とする。 use Symfony\Component\HttpFoundation\Response; public...

Custom Repository Class

Doctrineでは、Entityというものを使うけど、これは基本的にデータを保持するためだけのクラス。 で、実際に find などの様にデータベース上のデータをフェッチするには、Repository を使用する。 こんな感じ。(http://docs.symfony.gr.jp/symfony2/book/doctrine.htmlより引用) $product = $this->getDoctrine()        -$gt;getRepository('AcmeStoreBundle:Product')        -$gt;find($id); ...で、このgetRepositoryを見てみると、 /**  * Gets the repository for an entity class.  *  * @param string $entityName The name of the entity.  * @return EntityRepository The repository class.  */ public function...

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More