Skip to content

Commit

Permalink
フォーム生成サンプルの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro-adachi committed Apr 13, 2017
1 parent 65be318 commit 7e5d698
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
46 changes: 46 additions & 0 deletions app/Acme/Controller/EntityFormController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace Acme\Controller;

use Eccube\Application;
use Eccube\Entity\BaseInfo;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;

class EntityFormController
{
/**
* @Route("/entity-form")
*/
public function index(Application $app, Request $request)
{
$BaseInfo = new BaseInfo();

$builder = $app->form(
$BaseInfo,
[
'data_class' => BaseInfo::class,
]
);

$form = $builder->getForm();
$form->add('submit', SubmitType::class);

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// do stuff.
}

$template = "
{{ form_start(form) }}
{{ form_row(form) }}
{{ form_end(form) }}
";

$params = ['form' => $form->createView()];

return $app['twig']
->createTemplate($template)
->render($params);
}
}
19 changes: 19 additions & 0 deletions app/Acme/Entity/BaseInfoTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Acme\Entity;

use Doctrine\ORM\Mapping as ORM;
use Eccube\Annotation\EntityExt;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @EntityExt(target="Eccube\Entity\BaseInfo")
*/
trait BaseInfoTrait
{
/**
* @ORM\Column(name="company_name_vn", type="string", length=255, nullable=true, options={"eccube_form_render":true})
* @Assert\NotBlank(message="にゅうりょくしてくださいね!!!")
*/
public $company_name_vn;
}

0 comments on commit 7e5d698

Please sign in to comment.