前提・実現したいこと
EC-CUBE3のプラグインでオリジナルメニューの表示。
現在はオリジナルメニューの追加までできていて、メニューを選択するとエラーになります。
発生している問題・エラーメッセージ
Twig_Error_Runtime in Template.php line 487: Variable "form" does not exist in "__string_template__283ef8214125d3fcd7d25d73043851d03dcdefbc05ff095ca850bb1d87f8358f" at line 8.
該当のソースコード
serviceprovider.php
php
1 2public function register(BaseApplication $app) 3 { 4 // 独自コントローラ 5$app->match('admin/plugin/categorycontent/hello', 'Plugin\CategoryContent\Controller\CategoryContentController::index')->bind('plugin_CategoryContent_hello'); 6 7$app['config'] = $app->share($app->extend('config', function ($config) 8 { $config['nav'][0]['child'][] = array( 9'id' => 'categorycontent', 'name' => '規格登録', 'url' => 'plugin_CategoryContent_hello', 10); 11return $config; })); 12 13 14$app['form.types'] = $app->share($app->extend('form.types', function ($types) use ($app) { 15$types[] = new CategoryContentConfigType(); 16return $types; 17})); 18 19} 20
controller.php
php
1public function index(Application $app, Request $request) 2 { 3 $form->handleRequest($request); 4 if ($form->isSubmitted() && $form->isValid()) { 5 $data = $form->getData(); 6 } 7 return $app->render('CategoryContent/Resource/template/admin/config.twig', array( 8 'form' => $form->createView(), 9 )); 10 11 }
twigテンプレートはジェネレータで作成したものをそのまま使っています。
オリジナルメニューのURLは
http://ドメイン/html/admin/plugin/categorycontent/hello
になっています。
ご教示いただければと思います。何卒よろしくお願いいたします。
###追加
config.twig
php
1{% extends 'default_frame.twig' %} 2 3{% set menus = ['store', 'plugin', 'plugin_list'] %} 4 5{% block title %}CategoryContent画面{% endblock %} 6{% block sub_title %}CategoryContent設定{% endblock %} 7 8{% form_theme form 'Form/bootstrap_3_horizontal_layout.html.twig' %} 9 10{% block main %} 11 <form class="form-horizontal" method="post" action="{{ url('plugin_CategoryContent_config') }}"> 12 {{ form_widget(form._token) }} 13 <div class="row" id="aside_wrap"> 14 <div class="col-md-9"> 15 <div class="box"> 16 <div class="box-header"> 17 <h3 class="box-title">CategoryContent設定</h3> 18 </div><!-- /.box-header --> 19 <div class="box-body form-horizontal"> 20 {{ form_row(form.name) }} 21 </div><!-- /.box-body --> 22 </div><!-- /.box --> 23 </div><!-- /.col --> 24 <div class="col-md-3" id="aside_column"> 25 <div id="common_box" class="col_inner"> 26 <div id="common_button_box" class="box no-header"> 27 <div id="common_button_box__body" class="box-body"> 28 <div id="common_button_box__edit_button" class="row text-center"> 29 <div class="col-sm-6 col-sm-offset-3 col-md-12 col-md-offset-0"> 30 <button class="btn btn-primary btn-block btn-lg" type="submit">設定</button> 31 </div> 32 </div> 33 </div><!-- /.box-body --> 34 </div><!-- /.box --> 35 </div> 36 </div><!-- /.col --> 37 </div> 38 </form> 39{% endblock main %}
フォーム
CategoryContentConfigType.php
php
1class CategoryContentConfigType extends AbstractType 2{ 3 public function buildForm(FormBuilderInterface $builder, array $options) 4 { 5 6 $builder 7 ->add( 8 'name', 9 'text', 10 array( 11 'constraints' => array( 12 new Assert\NotBlank(), 13 ), 14 ) 15 ) 16 ->add( 17 'code', 18 'text', 19 array( 20 'constraints' => array( 21 new Assert\NotBlank(), 22 ), 23 ) 24 ); 25 26 27 28 } 29 30 public function getName() 31 { 32 return 'categorycontent'; 33 } 34 35 36}
##controller変更後
エラー
php
1 2ContextErrorException in CategoryContentController.php line 30: 3Notice: Undefined variable: form
controller
php
1public function index(Application $app, Request $request) 2 { 3 $form->handleRequest($request); 4 5 if ($form->isSubmitted() && $form->isValid()) { 6 $data = $form->getData(); 7 8 9 } 10 return $app->render('CategoryContent/Resource/template/admin/config.twig', array( 11 'form' => $form->createView(), 12 )); 13 }
##controller追記
エラー内容
php
1//1つめ 2Twig_Error_Runtime in Template.php line 230: 3An exception has been thrown during the rendering of a template ("User Warning: Unable to generate a URL for the named route "plugin_CategoryContent_config" as such route does not exist.") in "__string_template__283ef8214125d3fcd7d25d73043851d03dcdefbc05ff095ca850bb1d87f8358f" at line 11. 4 5//2つめ 6ContextErrorException in EccubeExtension.php line 172: 7User Warning: Unable to generate a URL for the named route "plugin_CategoryContent_config" as such route does not exist.
controller
php
1 public function index(Application $app, Request $request) 2 { 3 4 $form = $app['form.factory'] 5 ->createBuilder('categorycontent') 6 ->getForm(); 7 8 $form->handleRequest($request); 9 10 if ($form->isSubmitted() && $form->isValid()) { 11 $data = $form->getData(); 12 13 14 } 15 return $app->render('CategoryContent/Resource/template/admin/config.twig', array( 16 'form' => $form->createView(), 17 )); 18 }
回答2件
あなたの回答
tips
プレビュー