子域名问题
我正在解决 silverstripe 子域的问题,其他人编写了代码,因此任何帮助将不胜感激。
主网站(例如 www.mainwebsite.com)上有一个“关于我们”导航栏,我们希望“关于我们”对于任何子域(例如 subdomain.mainwebsite.com)消失。
我可以从Silverstripe后端看到,有一个“隐藏在子域名”功能,我勾选了它。然而,“关于我们”链接消失了一段时间,然后在主站点和子域的其他书籍中又出现了。
谁能指出正确的方向我该如何解决这个问题?如果您需要,我可以在这里复制任何代码。请帮忙。
谢谢大家, S:)
添加注释,我在我的站点 - 代码文件夹中的 page.php 中找到了此代码(如果有用的话
function ShowMenuInSubdomain()
{
$host = explode('.',$_SERVER['HTTP_HOST']);
$subdomain = $host[0];
if($subdomain != 'www' && $this->HideInSubdomains) {
return true;
}
}
添加注释),这里是主题 - 模板文件夹中 Page.ss 中的导航部分我正在使用
<div id="Header">
<div id="HeaderWrapper">
<div id="LogoWrapper"><a href="{$BaseHref}">$GetSubDomainHeaderImage</a></div>
<div id="Navigation">
<% cached 'Navigation', Aggregate(Page).Max(LastEdited) %>
<% include Navigation %>
<% end_cached %>
</div>
</div>
</div>
添加注释,在这里是我在模板中的 navigation.ss - 包含文件夹看起来像
<ul>
<% control Menu(1) %>
<% if ShowMenuInSubdomain %>
<% else %>
<li <% if Children %>class="hasChildren"<% end_if %>>
<a href="$Link" title="$Title.XML" class="$LinkingMode">$MenuTitle.XML <% if ShowMenuInSubdomain %>0<% end_if %></a>
<% if Children %>
<ul>
<% control Children %>
<li <% if Children %>class="hasChildren"<% end_if %>>
<a href="$Link" title="$Title.XML" class="$LinkingMode">$MenuTitle.XML</a>
<% if Children %>
<ul>
<% control Children %>
<ul class="thridUL{$Pos}">
<% if DisableLink %>
<li>
<span class="$LinkingMode thirdLevelTitle lookLikeALink">$MenuTitle.XML</span>
</li>
<% else_if ShowLabelInMenu==0 %>
<li>
<a href="$Link" title="$Title.XML" class="$LinkingMode thirdLevelTitle">$MenuTitle.XML</a>
</li>
<% end_if %>
<% if Children %>
<% control Children %>
<li>
<a href="$Link" title="$Title.XML" class="$LinkingMode">$MenuTitle.XML</a>
<% if Summary %>
<span class="menuSummary">
$Summary
<span class="menuSummaryThumb">$Thumbnail.PaddedImage(160, 160)</span>
</span>
<% end_if %>
</li>
<% end_control %>
<% end_if %>
</ul>
<div class="clear"> </div>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_if %>
<% end_control %>
<li id="calculatorWrapper">
<a id="Calculator" href="$distanceCalculator.Link" rel="shadowbox;height=800;width=1000"><span>Journey Planner</span></a>
</li> </ul>
抱歉,它有点长,但感谢您的帮助。谢谢。
大家好,它似乎有效 现在当我删除 <% 缓存时 '导航', 聚合(页).最大(最后编辑) %> <% end_cached %>在 page.ss 中。有人可以吗 请解释一下这是什么 行的意义还是什么呢?谢谢。
I am working on a silverstripe subdomains' issue, someone else did the code, so any help would be appreciated.
There is a "About Us" nav bar on the main website eg www.mainwebsite.com, and we would like the "About Us" to disappear for any subdomains eg subdomain.mainwebsite.com.
I can see from the Silverstripe backend, there is a 'Hide in Subdomains' function, and I ticked it. However, the "About Us" link disappears for some time and it comes back at other tomes on both main site and subdomains.
Can anybody point me to the right direction how can I fix this problem? I can copy any code here if you need. Please help.
Thanks heaps,
S:)
add comments, I have found this code in my page.php in my site - code folder if it is useful
function ShowMenuInSubdomain()
{
$host = explode('.',$_SERVER['HTTP_HOST']);
$subdomain = $host[0];
if($subdomain != 'www' && $this->HideInSubdomains) {
return true;
}
}
add comments, here is navigation part in Page.ss in the theme - templates folder I am using
<div id="Header">
<div id="HeaderWrapper">
<div id="LogoWrapper"><a href="{$BaseHref}">$GetSubDomainHeaderImage</a></div>
<div id="Navigation">
<% cached 'Navigation', Aggregate(Page).Max(LastEdited) %>
<% include Navigation %>
<% end_cached %>
</div>
</div>
</div>
add comments, here is what my navigation.ss in the templates - includes folder looks like
<ul>
<% control Menu(1) %>
<% if ShowMenuInSubdomain %>
<% else %>
<li <% if Children %>class="hasChildren"<% end_if %>>
<a href="$Link" title="$Title.XML" class="$LinkingMode">$MenuTitle.XML <% if ShowMenuInSubdomain %>0<% end_if %></a>
<% if Children %>
<ul>
<% control Children %>
<li <% if Children %>class="hasChildren"<% end_if %>>
<a href="$Link" title="$Title.XML" class="$LinkingMode">$MenuTitle.XML</a>
<% if Children %>
<ul>
<% control Children %>
<ul class="thridUL{$Pos}">
<% if DisableLink %>
<li>
<span class="$LinkingMode thirdLevelTitle lookLikeALink">$MenuTitle.XML</span>
</li>
<% else_if ShowLabelInMenu==0 %>
<li>
<a href="$Link" title="$Title.XML" class="$LinkingMode thirdLevelTitle">$MenuTitle.XML</a>
</li>
<% end_if %>
<% if Children %>
<% control Children %>
<li>
<a href="$Link" title="$Title.XML" class="$LinkingMode">$MenuTitle.XML</a>
<% if Summary %>
<span class="menuSummary">
$Summary
<span class="menuSummaryThumb">$Thumbnail.PaddedImage(160, 160)</span>
</span>
<% end_if %>
</li>
<% end_control %>
<% end_if %>
</ul>
<div class="clear"> </div>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_if %>
<% end_control %>
<li id="calculatorWrapper">
<a id="Calculator" href="$distanceCalculator.Link" rel="shadowbox;height=800;width=1000"><span>Journey Planner</span></a>
</li> </ul>
Sorry it is a bit long but any help is appreciated. Thanks.
Hi everyone, it seems to be working
now when I deleted <% cached
'Navigation',
Aggregate(Page).Max(LastEdited) %> <%
end_cached %> in page.ss. Can someone
please kindly explain what was this
line for or the meaning of it? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就这样做:
just do this:
由于您已经找到了 subodmain 检查的方法(“ShowMenuInSubdomain”),因此现在查找呈现菜单的模板。对于标准 Silverstripe 安装,这很可能是
/mysite/templates/Page.ss
或/mysite/templates/layout
中的文件之一。您的菜单可能会在如下所示的块内呈现:
您只需包装列表项,然后用一个控制块调用您的
ShowMenuInSubdomain
函数,如下所示:请发布相应的模板代码块,以防您“在这方面遇到麻烦了。
注意:我认为有一个“!” ShowMenuInSubdomain 函数中缺少该内容,因为它当前的读法类似于“if (HideInSubdomains) then ShowMenuInSubdomain is true”,因此有问题的行可能应该是:
(注意 $this- 之前的 '!' >HideInSubdomains)
编辑
首先,忘记
GetSubDomainMenu
函数,看起来好像它已经被很多东西取代了使用内置Menu
控件与ShowMenuInSubdomain
函数结合使用来进行子域检查的更清晰的解决方案。其次,忘记我关于丢失的“!”的注释。在上面的
$this->HideInSubdomains
之前。从该函数的使用方式来看,我可以看到它做了它应该做的事情,该函数只是以一种误导性的方式命名:ShowMenuInSubdomain
应该读取HideMenuInSubdomain
。令人困惑,但显然不是问题的根源。因此,从您迄今为止发布的代码来看,没有明显的错误,因此您应该尝试验证以下内容:
a)“navigation.ss”(不是您发布的我猜的.cc)实际上是渲染的模板吗?只需在文件中添加一些测试输出即可确定(并将“?flush = 1”添加到您的网址以清除模板缓存)
b) ShowMenuInSubdomain 函数实际上被调用了吗?让它在第一行返回一些字符串,例如“return“working””,然后将
$ShowMenuInSubdomain
添加到您的模板中,以防您仍然卡住,然后,您可以压缩 silverstripe 项目文件夹并将其放入某处可供下载(首先删除数据库访问凭据等关键信息!),以便我可以查看。
祝你好运!
编辑 II - 解决方案 - 最后:)
看起来好像您发现了有缺陷的代码部分。您删除的行应该缓存导航,因此不必每次渲染时都进行组装(我猜您熟悉“缓存”的概念)。请参阅有关部分缓存的silverstripe 文档以获取对此的进一步说明。请注意“聚合”下的第一个代码片段 - 它正是您已删除的代码。
但为什么删除缓存部分可以解决您的问题呢?事实上,答案很简单:由于您的缓存导航只会在编辑某些页面后更新,因此无论您是否在子域上,都不会调用子域检查功能,除非那时也一样。有时就是这么简单:)
as you've already found a method to the subodmain check for you ('ShowMenuInSubdomain'), look now for the template where the menu is rendered. for a standard silverstripe installation this is most probably
/mysite/templates/Page.ss
, or one of the files in/mysite/templates/layout
.your menu might be rendered inside a block like the following:
you just have to wrap the list item then with a control block calling your
ShowMenuInSubdomain
function like so:please post the corresponding template code block in case you're having trouble with this.
NOTE: i think there's a '!' missing in your ShowMenuInSubdomain function, as it currently reads like 'if (HideInSubdomains) then ShowMenuInSubdomain is true', so the line in question should probably be:
(watch out for the '!' before $this->HideInSubdomains)
EDIT
first, forget about the
GetSubDomainMenu
function, looks as though it's been replaced by the much cleaner solution of using the built-inMenu
control in conjunction withShowMenuInSubdomain
function for the subdomain check.second, forget about my note on the missing '!' before
$this->HideInSubdomains
above. from the way the function is used i can see that it does what it's supposed to, the function is just named in a misleading way:ShowMenuInSubdomain
should readHideMenuInSubdomain
. confusing, but not the source of the problem, apparently.so, from the code you've posted so far, there is no visible mistake, so you should try to verify the following:
a) is the 'navigation.ss' (NOT .cc as you've posted i guess) actually the template that's rendered? just add some test output inside the file to be sure (and add '?flush=1' to your url to clear the template cache)
b) does the
ShowMenuInSubdomain
function actually get called? make it return some string like 'return "working"' in the first line, then add$ShowMenuInSubdomain
to your templatein case you're still stuck then, you may zip your silverstripe project folder and put it somewhere for download (remove critical info like db access credentials first!), so i can have a look.
good luck!
EDIT II - SOLUTION - FINALLY :)
looks as though you found the flawed code part. the lines you've deleted were supposed to cache the navigation, so it doesn't have to get assembled each time it's rendered (i guess you're familiar with the concept of 'caching'). have a look at the silverstripe docs on partial caching for further explanations on this. watch out for the first code snippet under 'Aggregates' there - it's exactly the code you've deleted.
but why does removing the caching part solve your problem? in fact, the answer is quite simple: as your cached navigation will only update after editing some page, the subdomain checking function won't be called unless then too, wheter you're on a subdomain or not. it's that easy sometimes :)