バージョン選択

フォーラム

メニュー

オンライン状況

16 人のユーザが現在オンラインです。 (11 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 16
もっと...

サイト内検索

質問 > フロント機能 > URLのslug対応、APP_DEBUGデバックモードOFFでは、getURLができない

フロント機能

新規スレッドを追加する

フラット表示 前のトピック | 次のトピック
投稿者 スレッド
be-s
投稿日時: 2023/8/4 15:58
対応状況: 確認中
一人前
登録日: 2016/2/2
居住地: São Paulo
投稿: 115
URLのslug対応、APP_DEBUGデバックモードOFFでは、getURLができない
[EC-CUBE] 4.0.4
[レンタルサーバ] AWS EC2冗長化設定
[OS] Linux
[PHP] 7.3.*
[データベース] MySQL 5.7.*(RDS)
[WEBサーバ] Apache/2.4.*
[ブラウザ] Chrome
[セッション管理]PdoSessionHandler
[現象]



https://a-zumi.net/eccube4-url-slug/

上記対応で商品詳細をSLUG対応したのですが

商品詳細ページのリンクがtwig内で下記書き方で
リンクが
http://localhost/products/detail/*slug*
に変換されるのですが
.envのAPP_DEBUG=0にすると

http://localhost/products/detail/*product_id*
戻ってしまいます。

{{ url('product_detail', {id : Product.id} ) }}


こちらの原因わかりますでしょうか
なにとぞよろしくお願いいたします。

<?php
namespace Customize\Twig;

use Eccube\Entity\Product;
use Eccube\Repository\ProductRepository;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * Class RoutingExtension
 * @package Customize\Twig
 */
class RoutingExtension extends \Symfony\Bridge\Twig\RoutingExtension
{
    /**
     * @var ProductRepository
     */
    private $productRepository;
    /**
     * RoutingExtension constructor.
     * @param UrlGeneratorInterface $generator
     * @param ProductRepository $productRepository
     */
    public function __construct(UrlGeneratorInterface $generator, ProductRepository $productRepository)
    {
        parent::__construct($generator);

        $this->productRepository = $productRepository;
    }

    /**
     * スラッグを持っている場合はスラッグのURLを生成、
     * スラッグを持っていない場合はIDのURLを生成
     *
     * @param string $name
     * @param array $parameters
     * @param false $schemeRelative
     * @return string
     */
    public function getUrl($name, $parameters = [], $schemeRelative = false)
    {
        if ($name === "product_detail") {
            /** @var Product $product */
            $product = $this->productRepository->find($parameters["id"]);
            if($product->getCartKeyCd()) {
                // スラッグを持っている商品はスラッグのURLを生成
                return parent::getUrl("product_detail", ["id" => $product->getCartKeyCd()], $schemeRelative);
            } else {
                // スラッグを持っていない商品は商品IDのURLを生成
                return parent::getUrl("product_detail", ["id" => $parameters["id"]], $schemeRelative);
            }
        }
        return parent::getUrl($name, $parameters, $schemeRelative);
    }
}
フラット表示 前のトピック | 次のトピック


題名 投稿者 日時
 » URLのslug対応、APP_DEBUGデバックモードOFFでは、getURLができない be-s 2023/8/4 15:58
     Re: URLのslug対応、APP_DEBUGデバックモードOFFでは、getURLができない mcontact 2023/8/6 15:03
       Re: URLのslug対応、APP_DEBUGデバックモードOFFでは、getURLができない be-s 2023/8/8 11:46

 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は89,350名です
総投稿数は110,082件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2314
5
umebius
2085
6
yuh
1819
7
h_tanaka
1652
8
red
1570
9
mcontact
1304
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.