Symfony3ナレッジ
Entity
交差テーブル(中間テーブル)のアノテーション定義
Form
動的なForm名でtwigに埋め込む
{{ form_label(form["CustomerExtend"~i].CustomValue) }}
関連テーブル
ControllerからFormへのデータ引き渡し
$builder = $this->formFactory->createNamedBuilder( '', AddCartType::class, null, [ 'product' => $Product, 'id_add_product_id' => false, ] );
public function buildForm(FormBuilderInterface $builder, array $options) { /* @var $Product \Eccube\Entity\Product */ $Product = $options['product'];
ManyToManyで複数選択のチェックボックスフォームを作る
class ShopPaymentSelectType extends AbstractType { /** * @var PaymentRepository */ protected $paymentRepository; public function __construct(PaymentRepository $paymentRepository) { $this->paymentRepository = $paymentRepository; } /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { /** @var Shop $Shop */ $Shop = $options["data"]; $builder ->add( 'paymentIds', ChoiceType::class, [ 'choices' => $this->nameChoices(), 'expanded' => true, 'multiple' => true, 'data' => $Shop->getPaymentIds(), // デフォルト値設定 ] ); } private function nameChoices() { $choices = []; /** @var Payment $Payment */ foreach ($this->paymentRepository->findAll() as $Payment) { $choices[$Payment->getMethod()] = $Payment->getId(); } return $choices; } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults( [ 'data_class' => Shop::class, ] ); } }
便利コマンド
ルーティング一覧確認
bin/console debug:routerbin/console debug:router
イベントリスナー一覧確認
bin/console debug:event-dispatcher
サービス一覧の確認
bin/console debug:container
キャッシュ関連
OPCacheもクリアすること