Symfony blackknight467 StarRatingBundle无法找到模板

时间:2019-06-13 10:34:16

标签: php symfony twig symfony4 symfony-3.4

我已经在Symfony 3.4项目上安装了blackknight467 / StarRatingBundle,并在设置表单后显示以下错误:

  

无法找到模板“ StarRatingBundle :: rating.html.twig”(已查找   进入:/ var / www / test / app / Resources / views,   / var / www / test / vendor / symfony / symfony / src / Symfony / Bridge / Twig / Resources / views / Form)。

/src/AppBundle/Controller/CommentsController.php

$form = $this->createFormBuilder()
   ->add('review_rating', RatingType::class, ['stars' => 5])
   ->getForm();

return $this->render('@App\Comments\index.html.twig', ['form' => $form->createView()]);

/src/AppBundle/Resources/views/Comments/index.html.twig

{{form_widget(form.review_rating)}}

/vendor/blackknight467/star-rating-bundle/blackknight467/StarRatingBundle/Form/RatingType.php

namespace blackknight467\StarRatingBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;

class RatingType extends AbstractType
{

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $view->vars = array_replace($view->vars, [
            'stars' => $options['stars']
        ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'attr' => [
                'class' => 'rating',
            ],
            'scale' => 1,
            'stars' => 5,
        ]);
    }

    public function getParent()
    {
        return NumberType::class;
    }

    public function getName()
    {
        return 'rating';
    }
}

我已经在StackOverflow中寻找了类似的问题,但是即使通过解决这些问题也无法解决。我该如何解决?

0 个答案:

没有答案