Created
March 22, 2017 09:32
-
-
Save chihiro-adachi/80391e64950e295af000ce32d5ffa03e to your computer and use it in GitHub Desktop.
FormTypeのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file is part of EC-CUBE | |
* | |
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. | |
* | |
* http://www.lockon.co.jp/ | |
* | |
* This program is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU General Public License | |
* as published by the Free Software Foundation; either version 2 | |
* of the License, or (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program; if not, write to the Free Software | |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
*/ | |
namespace Eccube\Controller; | |
use Eccube\Application; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\Extension\Core\Type\TextType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
class TopController extends AbstractController | |
{ | |
public function index(Application $app) | |
{ | |
$builder = $app['form.factory'] | |
->createBuilder( | |
CompanyType::class, | |
['name' => '株式会社ロックオン'], | |
['eccube.repository.base_info' => $app['eccube.repository.base_info']] | |
); | |
$form = $builder->getForm(); | |
dump($form->createView()); | |
return $app->render('index.twig'); | |
} | |
} | |
class CompanyType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$BaseInfo = $options['eccube.repository.base_info']->get(); | |
dump($BaseInfo); | |
$builder->add('name', TextType::class); | |
} | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setDefault('eccube.repository.base_info', null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment