再次,我很难在Pimcore 4中进行类映射工作。这次我想扩展文档页面类。这曾经在较旧版本中没有问题,但是现在我无法正常工作。
我在classmap.php中从classmap.example.php中复制了此示例:
网站/config/classmap.php:
return [
"Document\Page" => "Website\Model\Document\Page",
]
网站/型号/网站/模型/document/pagp.php:
namespace WebsiteModel;
use PimcoreModelDocument;
class Page extends DocumentPage {
public function getPublicPath() {
return $this->getFullPath();
}
}
预期的结果是我可以在每个文档页面对象上调用getPublicpath()。但这不起作用。相反,我会收到以下错误:
Call to undefined method getPublicPath in class PimcoreModelDocumentPage
我该如何工作?
您的命名空间声明是错误的。应该是:
namespace WebsiteModelDocument;
所以整个班级看起来像这样:
<?php
namespace WebsiteModelDocument;
use PimcoreModelDocument;
class Page extends DocumentPage {
public function getPublicPath() {
return $this->getFullPath();
}
}
更新代码后不要忘记清除缓存!