LoginSignup
3
1

More than 5 years have passed since last update.

【初めてのSymfony2】Bundleをgenerateしてみる

Last updated at Posted at 2015-04-08

(正直)あんまり乗り気ではないが、symfony2を取り扱ってみることにした時のメモ
このBundleってのが自分はまだしっくり来ないんだなー・・・・

前にやったこと

環境

vagrantで構築

  • Guest OS
    • CentOS6.4 x86

事前準備に必要なもの

出来上がるもの

参考にしたサイト

generate:bundleを使って見る

その前にhelpを読んでみる

/path/to/leaning-symfony2
php app/console generate:bundle --help

helpを読んでなんとなく掴めてきたので作ってみる

作るBundle

管理画面用のログイン画面のBundleを作る

/path/to/leaning-symfony2
php app/console generate:bundle

#namespace
Bundle namespace: Admin/LoginBundle

#bundle名
Bundle name [AdminLoginBundle]:LoginBundle

#Bundleのディレクトリ
Target directory [/synced/leaning-symfony2/src]:

#configの種類
Configuration format (yml, xml, php, or annotation): annotation

# 他のbundleの構成の必要なディレクトリも作成するか?
Do you want to generate the whole directory structure [no]?
 "annotation" format.

# bundleの作成の最終確認
Do you confirm generation [yes]?

# kernelをupdateするか?
Confirm automatic update of your Kernel [yes]?
# routingをupdateするか?
Confirm automatic update of the Routing [yes]?

ざっとこんな感じで作成した

どんなものが作成されたのか確認してみた

generateコマンドってのが何をつくるのかがよくわからないので確認してみる

/path/to/leaning-symfony2
git st
# On branch add_bootstrap
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   app/AppKernel.php
#   modified:   app/config/routing.yml
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   src/Admin/
no changes added to commit (use "git add" and/or "git commit -a")

app/AppKernel.phpapp/config/routing.yml が変更されて src/Adminが追加されている

app/AppKernel.php

/path/to/leaning-symfony2
git diff app/AppKernel.php
diff --git a/app/AppKernel.php b/app/AppKernel.php
index bccaf38..9536966 100644
--- a/app/AppKernel.php
+++ b/app/AppKernel.php
@@ -17,6 +17,7 @@ class AppKernel extends Kernel
             new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
             new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
             new AppBundle\AppBundle(),
+            new Admin\LoginBundle\LoginBundle(),
         );

         if (in_array($this->getEnvironment(), array('dev', 'test'))) {

app/AppKernel.php はクラスローダー的な役割なのかな

app/config/routing.yml

/path/to/leaning-symfony2
git diff app/config/routing.yml
diff --git a/app/config/routing.yml b/app/config/routing.yml
index 8eadc31..cd7a99d 100644
--- a/app/config/routing.yml
+++ b/app/config/routing.yml
@@ -1,3 +1,8 @@
+admin_login:
+    resource: "@LoginBundle/Controller/"
+    type:     annotation
+    prefix:   /
+
 app:
     resource: "@AppBundle/Controller/"
     type:     annotation

resourceの設定が追加されたみたい

src/Admin

/path/to/leaning-symfony2
rc/Admin/
└── LoginBundle
    ├── Controller
    │   └── DefaultController.php
    ├── DependencyInjection
    │   ├── Configuration.php
    │   └── LoginExtension.php
    ├── LoginBundle.php
    ├── Resources
    │   ├── config
    │   │   └── services.xml
    │   └── views
    │       └── Default
    │           └── index.html.twig
    └── Tests
        └── Controller
            └── DefaultControllerTest.php

MVCとそれっぽい設定ファイル郡が追加されたみたい

最後に

BUndle直下にある(今回で言うと src/Admin/Bundle/LoginBundle/AdminLoginBundle.php が何に使っていいのかよくわからない・・・・

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1