1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

新規ページ作成

Last updated at Posted at 2018-12-26

はじめに

前回の続き
/sampleに新規ページを作成する。

ページ追加

Controller

src/Eccube/Controller/UserDataController.phpなどをCustomizeにコピー
src/Eccube/Controller/UserDataController.php → app/Customize/Controller/SamplePageController.php

app/Customize/Controller/SamplePageController.php
namespace Customize\Controller;

use Eccube\Controller\AbstractController;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Product;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\ProductRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class SamplePageController extends AbstractController
{
    /** @var BaseInfo */
    protected $baseInfo;

    /** @var Product */
    protected $productRepository;

    /**
     * SamplePageController constructor.
     * @param BaseInfoRepository $baseInfoRepository
     * @param ProductRepository $productRepository
     */
    public function __construct(
        BaseInfoRepository $baseInfoRepository,
        ProductRepository $productRepository
    )
    {
        $this->baseInfo = $baseInfoRepository->get();
        $this->productRepository = $productRepository;
    }

    /**
     * @Route("/sample/{id}", name="sample_index")
     * @Template("Sample/index.twig")
     */
    public function index($id)
    {
        $product = $this->productRepository->find($id);

        return [
            'shop_name' => $this->baseInfo->getShopName(),
            'product_name' => $product->getName(),
        ];
    }
}

Template

app/template/default/Sample/index.twig
{% extends 'default_frame.twig' %}

{% block main %}

店舗名は"{{ shop_name }}"です。<br/>
商品名は"{{ product_name }}"です。<br/>

{% endblock %}

ブラウザよりアクセス

/sample/1 でページ表示できたがヘッダ部/フッタ部が表示されない

dtb_page/dtb_page_layout

前回調べたとき、ここにデータがないとページレイアウトが表示されない感じだったので...

INSERT INTO `dtb_page` (`id`, `master_page_id`, `page_name`, `url`, `file_name`, `edit_type`, `author`, `description`, `keyword`, `create_date`, `update_date`, `meta_robots`, `meta_tags`, `discriminator_type`) VALUES (NULL, NULL, 'サンプルインデックスページ', 'sample_index', 'Sample/index', 2, NULL, NULL, NULL, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'noindex', NULL, 'page');

-- PAGE_IDはdtb_pageのid
INSERT INTO `dtb_page_layout` (`page_id`, `layout_id`, `sort_no`, `discriminator_type`) VALUES (PAGE_ID, 2, 41, 'pagelayout');

ブラウザよりアクセス

/sample/1 でページ表示できたしヘッダ部/フッタ部も表示された

#まとめ
手動でdtb_page/dtb_page_layoutにデータをInsertしないといけないのかよく分からないけど、CotrollerとTemplateを作成し、dtb_page/dtb_page_layoutにデータを入れることで実現できた。

#参照
EC-CUBE 開発コミュニティ - フォーラム

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?