扩展Eventnews的Location/Organizer模型后前端自定义字段不显示问题
扩展tx_eventnews的Location/Organizer模型后自定义字段无法在前端显示
尝试扩展tx_eventnews的Location和Organizer模型,后端功能正常,数据能正常保存到数据库,但自定义字段无法在前端显示。通过NewsController的signalslot「detailaction」可以从自定义仓库获取值,但按官方文档的直接扩展方法应该可行,这种 workaround 显得多余。
前端调试newsItem.location和newsItem.organizer时,仅能渲染默认字段,无法显示新增的自定义字段。注:调试过程中已多次在安装工具中清除缓存。
ext_localconf.php 配置
$GLOBALS['TYPO3_CONF_VARS']['EXT']['eventnews']['classes']['Domain/Model/News'][] = 'my_website_extension'; $GLOBALS['TYPO3_CONF_VARS']['EXT']['eventnews']['classes']['Domain/Model/Location'][] = 'my_website_extension'; $GLOBALS['TYPO3_CONF_VARS']['EXT']['eventnews']['classes']['Domain/Model/Organizer'][] = 'my_website_extension';
自定义News模型(Classes\Domain\Model\News)
因未扩展News模型时无法生效,尝试扩展了eventnews的News模型:
/** * News */ class News extends \GeorgRinger\Eventnews\Domain\Model\News { /** * organizer * * @var \ThisIs\MyWebsiteExtension\Domain\Model\Organizer */ protected $organizer = null; /** * location * * @var \ThisIs\MyWebsiteExtension\Domain\Model\Location */ protected $location = null; /** * Returns the organizer * * @return \ThisIs\MyWebsiteExtension\Domain\Model\Organizer $organizer */ public function getOrganizer(): ?\ThisIs\MyWebsiteExtension\Domain\Model\Organizer { return $this->organizer; } /** * Sets the organizer * * @param \ThisIs\MyWebsiteExtension\Domain\Model\Organizer $organizer * @return void */ public function setOrganizer($organizer) { $this->organizer = $organizer; } /** * Returns the location * * @return \ThisIs\MyWebsiteExtension\Domain\Model\Location $location */ public function getLocation(): ?\ThisIs\MyWebsiteExtension\Domain\Model\Location { return $this->location; } /** * Sets the location * * @param \ThisIs\MyWebsiteExtension\Domain\Model\Location $location * @return void */ public function setLocation($location) { $this->location = $location; } }
自定义Location模型(Classes\Domain\Model\Location)
/** * Location */ class Location extends \GeorgRinger\Eventnews\Domain\Model\Location { /** * @var string */ protected $telephone; /** * @var string */ protected $isOnline; /** * @return string */ public function getTelephone(): string { return $this->telephone; } /** * @param string $telephone */ public function setTelephone(string $telephone): void { $this->telephone = $telephone; } /** * @return string */ public function getIsOnline(): string { return $this->isOnline; } /** * @param string $isOnline */ public function setIsOnline(string $isOnline): void { $this->isOnline = $isOnline; } }
Extbase持久化配置(Configuration\Extbase\Persistence\Classes.php)
不确定是否需要在表名外添加属性映射,两种方式都尝试过:
return [ \ThisIs\MyWebsiteExtension\Domain\Model\News::class => [ 'tableName' => 'tx_eventnews_domain_model_news', ], \ThisIs\MyWebsiteExtension\Domain\Model\Location::class => [ 'tableName' => 'tx_eventnews_domain_model_location', ], \ThisIs\MyWebsiteExtension\Domain\Model\Organizer::class => [ 'tableName' => 'tx_eventnews_domain_model_organizer', ], ];
ext_tables.sql 配置
# # Extend table structure for table 'tx_eventnews_domain_model_location' # CREATE TABLE tx_eventnews_domain_model_location ( telephone varchar(255) DEFAULT '' NOT NULL, is_online tinyint(4) DEFAULT '0' NOT NULL, ); # # Extend table structure for table 'tx_eventnews_domain_model_organizer' # CREATE TABLE tx_eventnews_domain_model_organizer ( email varchar(255) DEFAULT '' NOT NULL, telephone varchar(255) DEFAULT '' NOT NULL, website varchar(255) DEFAULT '' NOT NULL, );
TCA配置无问题,故未列出。
更新:扩展tx_news本身时一切正常,但扩展基于tx_news的eventnews时无法正常工作。
内容的提问来源于stack exchange,提问作者Kees Sonnema
相关产品推荐
相关产品推荐

