lam*_*ade 7 typo3 realurl extbase
我有一个列表和显示操作的扩展名.目前此扩展程序可以显示在多个页面上:
/page-1/
/page-2/subpage/
Run Code Online (Sandbox Code Playgroud)
我已经配置了realurl这样的:
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']=array (
'encodeSpURL_postProc' => array('user_encodeSpURL_postProc'),
'decodeSpURL_preProc' => array('user_decodeSpURL_preProc'),
'_DEFAULT' => array (
…
'postVarSets' => array(
'_DEFAULT' => array(
'controller' => array(
array(
'GETvar' => 'tx_extension_plugin[controller]',
'noMatch' => 'bypass',
),
),
'extension' => array(
array(
'GETvar' => 'tx_extension_plugin[action]',
),
array(
'GETvar' => 'tx_extension_plugin[controller]',
),
array(
'GETvar' => 'tx_extension_plugin[value]',
'lookUpTable' => array(
'table' => 'table',
'id_field' => 'uid',
'alias_field' => 'name',
'addWhereClause' => ' AND NOT deleted AND NOT hidden',
…
);
function user_decodeSpURL_preProc(&$params, &$ref) {
$params['URL'] = str_replace('page-1/', 'page-1/extension/', $params['URL']);
}
function user_encodeSpURL_postProc(&$params, &$ref) {
$params['URL'] = str_replace('page-1/extension/', 'page-1/', $params['URL']);
}
Run Code Online (Sandbox Code Playgroud)
现在我得到的网址如下:
/page-1/ /* shows list */
/page-1/Action/show/name-of-single-element /* single view */
Run Code Online (Sandbox Code Playgroud)
我真正想要的是这个:
/page-1/name-of-single-element /* single view */
Run Code Online (Sandbox Code Playgroud)
如何摆脱动作和控制器?
如果我删除:
array('GETvar' => 'tx_extension_plugin[action]'),
array('GETvar' => 'tx_extension_plugin[controller]'),
Run Code Online (Sandbox Code Playgroud)
它将参数附加到URL.
使用f:link.actionVH 时无法避免添加所有内容,而是需要使用f:link.page并仅传递必需的参数,示例:
<f:link.page additionalParams="{article : article.uid}" class="more" title="{article.name}">show article</f:link.page>
Run Code Online (Sandbox Code Playgroud)
它会生成url
/current/page/?article=123
Run Code Online (Sandbox Code Playgroud)
要么
/current/page/we-added-realurl-support-for-article
Run Code Online (Sandbox Code Playgroud)
在你的插件的第一个动作(可能list)中,show如果给定param存在,你只需要将请求转发给动作:
public function listAction() {
if (intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('article'))>0) $this->forward('show');
// Rest of code for list action...
}
Run Code Online (Sandbox Code Playgroud)
并可能改变签名 show
public function showAction() {
$article = $this->articleRepository->findByUid(intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('article')));
if ($article == null) {
$this->redirectToUri($this->uriBuilder->reset()->setTargetPageUid($GLOBALS['TSFE']->id)->build());
}
// Rest of code for show action...
}
Run Code Online (Sandbox Code Playgroud)
小智 6
如果URIbuilder使用,您还可以使用配置:
features.skipDefaultArguments = 1
Run Code Online (Sandbox Code Playgroud)
例如;
# if enabled, default controller and/or action is skipped when creating URIs through the URI Builder
plugin.tx_extension.features.skipDefaultArguments = 1
Run Code Online (Sandbox Code Playgroud)
我将此配置与realurl旁路结合使用
'postVarSets' => array(
'_DEFAULT' => array(
'extbaseParameters' => array(
array(
'GETvar' => 'tx_extension_plugin[action]',
'noMatch' => 'bypass',
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8985 次 |
| 最近记录: |