質問 > 管理機能 > レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string |
管理機能
スレッド表示 | 新しいものから | 前のトピック | 次のトピック | 下へ |
投稿者 | スレッド |
---|---|
d.y.m |
投稿日時: 2023/9/25 16:27
対応状況: −−−
|
新米 ![]() ![]() 登録日: 2023/9/25 居住地: 投稿: 4 |
レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string ▼テンプレート
[EC-CUBE] EC-CUBE4.2.0 [レンタルサーバ] 仮想環境 [OS] Linux ubuntu-focal 5.4.0 [PHP] PHP7.4 [データベース] MySQL 8.0.34 [WEBサーバ] Apache/2.4.41 (Ubuntu) [ブラウザ] Chorome [導入プラグインの有無] [カスタマイズの有無] ページ管理の編集画面で新しい項目を追加 [現象] 現在ローカル環境でEC-CUBEのカスタマイズについて学習しております。ページ管理の編集画面で新しい項目を追加しようと思い、項目の追加自体はできたのですが、レイアウト管理の編集画面に入ろうとすると「Object of class Eccube\Entity\PageLayout could not be converted to string」と表示されてしまいます。 レイアウトについてのファイルは変更しておらず、原因を探ろうとしても参考になる記事が無かったのでこちらでご質問させていただきます。 [エラー箇所] src/Eccube/Controller/Admin/Content/LayoutController.php:232 'form' => $form->createView(), [変更・追加した内容] 【PageTrait.php】 trait PageTrait { /** * @var integer|null * @ORM\Column(name="parentpage", type="integer", length=255, nullable=true) */ private $parentpage; /** * @return integer|null */ public function getParentPage() { return $this->parentpage; } /** * @param integer|null $parentpage * @return PageTrait */ public function setParentPage($parentpage = null) { $this->parentpage = $parentpage; return $this; } } 【PageController.php】 if ($form->isSubmitted() && $form->isValid()) { $Page = $form->getData(); if (!$isUserDataPage) { $Page ->setUrl($PrevPage->getUrl()) ->setFileName($PrevPage->getFileName()) ->setParentPage($Page->getParentPage()) ->setName($Page->getName()); } // DB登録 $this->entityManager->persist($Page); $this->entityManager->flush(); 【MainEditTypeExtension.php】 class MainEditTypeExtension extends AbstractTypeExtension { /** * @var PageRepository */ protected $pageRepository; /** * @param PageRepository $pageRepository */ public function __construct(PageRepository $pageRepository) { $this->pageRepository = $pageRepository; } public static function getExtendedTypes(): iterable { yield MainEditType::class; } public function buildForm(FormBuilderInterface $builder, array $options) { $pages = $this->pageRepository->findAll(); $choices = []; foreach ($pages as $page) { $name = $page->getName(); $id = $page->getId(); if($id!=0){ $choices[$name] = $id; } } $builder ->add('parentpage', ChoiceType::class, [ 'choices' => $choices, 'required' => false, 'mapped' => true, 'placeholder' => '---', ]); } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver ->setDefaults([ 'data_class' => Page::class, ]); } /** * {@inheritdoc} */ public function getBlockPrefix() { return 'main_edit'; } } |
mcontact |
投稿日時: 2023/9/25 17:24
対応状況: −−−
|
神 ![]() ![]() 登録日: 2022/1/22 居住地: 投稿: 1063 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string EC-CUBEログを確認できますか?
どのようなエラーが出ますでしょうか? EC-CUBEのログであれば、var/log/prod/site-yyyy-mm-dd.log に「システムエラーが発生しました」といった行がありましたらご提示ください。 dtb_pageテーブルをカスタマイズして様に見えますが、そちらが影響しているかと思います。
|
d.y.m |
投稿日時: 2023/9/25 18:13
対応状況: −−−
|
新米 ![]() ![]() 登録日: 2023/9/25 居住地: 投稿: 4 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string mcontact様
早速のご連絡ありがとうございます。 /var/log/prodを確認したのですが、私の設定の問題なのかエラーメッセージが残っておりません。 はい。dtb_pageテーブルを拡張してparentpageという列を追加したのですが、やはりこれが不味かったのでしょうか?レイアウトにはそこまで影響がないと思ったのですが。 |
mcontact |
投稿日時: 2023/9/26 9:18
対応状況: −−−
|
神 ![]() ![]() 登録日: 2022/1/22 居住地: 投稿: 1063 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string > /var/log/prodを確認したのですが、私の設定の問題なのかエラーメッセージが残っておりません。
デバッグモードなどにしていますか? > はい。dtb_pageテーブルを拡張してparentpageという列を追加したのですが、やはりこれが不味かったのでしょうか?レイアウトにはそこまで影響がないと思ったのですが。 EC-CUBE本体をカスタマイズするのであれば、何かしらのカスタマイズによる影響は受けます。 カスタマイズ内容に合わせて、開発および動作確認をする事が必要です。 https://www.thank-u.net/blog/eccube/required_skills_for_eccube/
|
d.y.m |
投稿日時: 2023/9/26 14:24
対応状況: −−−
|
新米 ![]() ![]() 登録日: 2023/9/25 居住地: 投稿: 4 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string mcontact様
参考記事拝見させていただきました。 サイトや書籍を見ながら学習を進めていましたが、スキル不足を痛感しました。 logについてですが、.envをAPP_ENV=devにしていたのでprodにはログが残っていない状態でした。一度prodに変更して再度確認したら下記のようなエラーメッセージが出ていました。(※どこまで必要かわからなかったので、出力されたものすべてコピーしてます) [2023-09-26T10:58:42.582547+09:00] app.ERROR [301e112d] [f28eb1c] [1] [Eccube\Log\Logger:log:68] - システムエラーが発生しました。 ["Object of class Eccube\\Entity\\PageLayout could not be converted to string","/var/www/ec-cube/vendor/symfony/doctrine-bridge/Form/Type/DoctrineType.php",59,"#0 /var/www/ec-cube/vendor/symfony/form/ChoiceList/Factory/DefaultChoiceListFactory.php(185): Symfony\\Bridge\\Doctrine\\Form\\Type\\DoctrineType::createChoiceLabel()\n#1 /var/www/ec-cube/vendor/symfony/form/ChoiceList/Factory/DefaultChoiceListFactory.php(266): Symfony\\Component\\Form\\ChoiceList\\Factory\\DefaultChoiceListFactory::addChoiceView()\n#2 /var/www/ec-cube/vendor/symfony/form/ChoiceList/Factory/DefaultChoiceListFactory.php(148): Symfony\\Component\\Form\\ChoiceList\\Factory\\DefaultChoiceListFactory::addChoiceViewsFromStructuredValues()\n#3 /var/www/ec-cube/vendor/symfony/form/ChoiceList/Factory/PropertyAccessDecorator.php(230): Symfony\\Component\\Form\\ChoiceList\\Factory\\DefaultChoiceListFactory->createView()\n#4 /var/www/ec-cube/vendor/symfony/form/ChoiceList/Factory/CachingFactoryDecorator.php(235): Symfony\\Component\\Form\\ChoiceList\\Factory\\PropertyAccessDecorator->createView()\n#5 /var/www/ec-cube/vendor/symfony/form/Extension/Core/Type/ChoiceType.php(498): Symfony\\Component\\Form\\ChoiceList\\Factory\\CachingFactoryDecorator->createView()\n#6 /var/www/ec-cube/vendor/symfony/form/Extension/Core/Type/ChoiceType.php(255): Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType->createChoiceListView()\n#7 /var/www/ec-cube/vendor/symfony/form/ResolvedFormType.php(147): Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType->buildView()\n#8 /var/www/ec-cube/vendor/symfony/form/ResolvedFormType.php(144): Symfony\\Component\\Form\\ResolvedFormType->buildView()\n#9 /var/www/ec-cube/vendor/symfony/form/Form.php(1062): Symfony\\Component\\Form\\ResolvedFormType->buildView()\n#10 /var/www/ec-cube/vendor/symfony/form/Form.php(1065): Symfony\\Component\\Form\\Form->createView()\n#11 /var/www/ec-cube/src/Eccube/Controller/Admin/Content/LayoutController.php(232): Symfony\\Component\\Form\\Form->createView()\n#12 /var/www/ec-cube/vendor/symfony/http-kernel/HttpKernel.php(153): Eccube\\Controller\\Admin\\Content\\LayoutController->edit()\n#13 /var/www/ec-cube/vendor/symfony/http-kernel/HttpKernel.php(75): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n#14 /var/www/ec-cube/vendor/symfony/http-kernel/Kernel.php(202): Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n#15 /var/www/ec-cube/index.php(83): Symfony\\Component\\HttpKernel\\Kernel->handle()\n#16 {main}"] また、同様の仮想環境を構築して同じカスタマイズを検証した結果、レイアウト管理画面でも特に問題が発生しませんでした。 |
h_tanaka |
投稿日時: 2023/9/26 15:22
対応状況: −−−
|
神 ![]() ![]() 登録日: 2016/7/22 居住地: 愛媛県 投稿: 1511 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string エラーをよく読んで理解してください。
PageLayout オブジェクトを文字列に変換することができません。というようなエラーです。 ChoiceType の choices に値として文字列を指定していますが、 data_class には Page::class を指定しているからではないでしょうか。 オブジェクトを扱うなら、 ChoiceType ではなく EntityType で扱うべきです。 src/Eccube/Form/Type/Shopping/OrderType.php の Payment を参考にしてもらえるとわかりやすいかと思います。
|
h_tanaka |
投稿日時: 2023/9/28 11:15
対応状況: −−−
|
神 ![]() ![]() 登録日: 2016/7/22 居住地: 愛媛県 投稿: 1511 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string twig 側で
{{ PageLayout }} のようなコードを書いてはいないでしょうか? twig ではオブジェクトを出力することはできないため、上記のようなコードがあると「Object of class Eccube\Entity\PageLayout could not be converted to string」のエラーが発生します。
|
d.y.m |
投稿日時: 2023/9/28 14:17
対応状況: −−−
|
新米 ![]() ![]() 登録日: 2023/9/25 居住地: 投稿: 4 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string h_tanaka様
twigはpage_editとlayoutの両方を確認しましたが、{{PageLayout}}のような記述は見当たりませんでした。 また、レイアウトの新規作成及びページにレイアウトを適用しない限りレイアウトの編集画面には入れるようでした。 なお、別途仮想環境を再度構築して同じカスタマイズを検証した結果、レイアウト管理画面に移っても表題の問題が発生しなかったので、変更を加える際に何か間違えたのかもしれません(参考サイトを見ながら色々触ったのでそこで問題が発生?) このスレッドで質問するのは恐縮なのですが、教えていただいたEntityTypeでフォームの作成自体はできたのですが、ChoiceTypeで作成した時のように更新するとdtb_pageに反映されなくなりました。参考になる記事を探したのですが、原因がわからずご教授いただけますでしょうか? 【MainEditTypeExtension.php】 public static function getExtendedTypes(): iterable { yield MainEditType::class; } public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('parentpage', EntityType::class, [ 'class' => Page::class, 'mapped' => false, 'placeholder' => '---', 'choice_label' => 'name', 'required' => false, 'query_builder' => function (Pagerepository $er) { return $er ->createQueryBuilder('p') ->where('p.id <> 0') ->orderBy('p.id', 'ASC'); }, ]); } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver ->setDefaults([ 'data_class' => Page::class, ]); } 【PageController.php】 if ($form->isSubmitted() && $form->isValid()) { $Page = $form->getData(); if (!$isUserDataPage) { $Page ->setUrl($PrevPage->getUrl()) ->setFileName($PrevPage->getFileName()) ->setParentPage($Page->getParentPage()) ->setName($Page->getName()); } // DB登録 $this->entityManager->persist($Page); $this->entityManager->flush(); |
h_tanaka |
投稿日時: 2023/9/28 15:24
対応状況: −−−
|
神 ![]() ![]() 登録日: 2016/7/22 居住地: 愛媛県 投稿: 1511 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string インデントがないので読みにくいです。。
コードの埋め込みは [ code ] 〜 [/ code ] タグで囲んでください。
|
h_tanaka |
投稿日時: 2023/9/28 15:32
対応状況: −−−
|
神 ![]() ![]() 登録日: 2016/7/22 居住地: 愛媛県 投稿: 1511 |
Re: レイアウト管理でObject of class Eccube\Entity\PageLayout could not be converted to string 'mapped' => false,
が指定されているからではないでしょうか。 FormType で指定されたフォームは保存処理を書かなくても自動で保存してくれます。 自動保存するかどうかの 'mapped' オプションはデフォルト true ですが、 false を指定しているため、自力で保存処理を実装する必要があります。
|
スレッド表示 | 新しいものから | 前のトピック | 次のトピック | トップ |