1

Symfony CMF と AutoRoutingBundle をアプリケーションに統合した後、コントローラーとテンプレートのドキュメントに従いました。私の問題は#50450338に似ていますが、引数に正しく名前を付けても問題を解決できません。

Pageドキュメントを作成すると、そのドキュメントAutoRouteが自動的に作成されますが、コントローラーを使用してそのページを表示しようとすると$contentDocument、ドキュメントが示唆するようにコントローラー アクションにパラメーターを取得できません。引数を追加すると、次のエラーが発生します。

「App\ContentBundle\Controller\PageController::pageaction()」の引数 $contentDocument を解決できませんでした。コントローラーをサービスとして登録するのを忘れたか、「controller.service_arguments」でタグ付けし忘れた可能性がありますか?

コントローラーが提案どおりにタグ付けされている場合でも、エラーは解決しません。

引数なしでページ テンプレートをレンダリングすると、表示できますが、属性$contentDocumentを取得できません。Page

ここに私のPage文書があります:

/**
 * Class Page
 * @package App\ContentBundle\Document
 *
 * @Document(translator="attribute", referenceable=true)
 */
class Page implements
    TranslatableInterface,
    RouteReferrersReadInterface
{
    /**
     * @var string
     * @Id()
     */
    protected $id;

    /**
     * @var string
     * @Uuid()
     */
    protected $uuid;

    /**
     * @var object
     * @ParentDocument()
     */
    protected $parent;

    /**
     * @Referrers(
     *     referringDocument="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route",
     *     referencedBy="content"
     * )
     */
    protected $routes;

    /**
     * @var string|boolean
     * @Locale()
     */
    private $locale;

    /**
     * @var string|null
     * @Nodename()
     */
    private $slug;

    /**
     * @var string|null
     * @Field(type="string", nullable=false)
     */
    private $title;

    /**
     * @var \Sonata\BlockBundle\Model\BlockInterface[]
     * @Children()
     */
    private $blocks;

    public function __construct ()
    {
        $this->blocks = [];
    }

    /**
     * @return string
     */
    public function getId ()
    : string
    {
        return $this->id;
    }

    /**
     * @return object
     */
    public function getParentDocument ()
    : object
    {
        return $this->parent;
    }

    /**
     * @param object $parent
     */
    public function setParentDocument ( $parent )
    : void
    {
        $this->parent = $parent;
    }

    /**
     * @return mixed
     */
    public function getRoutes ()
    {
        return $this->routes;
    }

    /**
     * @return bool|string
     */
    public function getLocale ()
    {
        return $this->locale;
    }

    /**
     * @param bool|string $locale
     */
    public function setLocale ( $locale )
    : void
    {
        $this->locale = $locale;
    }

    /**
     * @return string|null
     */
    public function getSlug ()
    : ?string
    {
        return $this->slug;
    }

    /**
     * @param string|null $slug
     */
    public function setSlug ( ?string $slug )
    : void
    {
        $this->slug = $slug;
    }

    /**
     * @return string|null
     */
    public function getTitle ()
    : ?string
    {
        return $this->title;
    }

    /**
     * @param string|null $title
     */
    public function setTitle ( ?string $title )
    : void
    {
        $this->title = $title;
    }

    /**
     * @return \Sonata\BlockBundle\Model\BlockInterface[]
     */
    public function getBlocks ()
    : array
    {
        return $this->blocks;
    }

    /**
     * @param \Sonata\BlockBundle\Model\BlockInterface[] $blocks
     */
    public function setBlocks ( array $blocks )
    : void
    {
        $this->blocks = $blocks;
    }
}

Symfony CMF 構成:

cmf_routing:
    chain:
        routers_by_id:
            router.default: 200
            cmf_routing.dynamic_router: 100
    dynamic:
        persistence:
            phpcr:
                enabled: true
                manager_name: default
        controllers_by_class:
            App\ContentBundle\Document\Page: App\ContentBundle\Controller\PageController::pageAction

cmf_routing_auto.yml私のバンドルで:

App\ContentBundle\Document\Page:
    definitions:
        main:
            uri_schema: /{slug}
    token_providers:
        slug: [content_method, {method: getSlug}]

そしてコントローラーのアクション:

    /**
     * @Template()
     * @param $contentDocument
     *
     * @return array
     */
    public function pageAction ( $contentDocument )
    {
        return [
            'page' => $contentDocument,
        ];
    }
4

0 に答える 0