PHP需要/包含文件(PHP require/include file)
我有以下程序结构:
Root directory:-----index.php |-------TPL directory |-------------header.php |-------------index.php |-------------footer.php php file loading structure: Root directory:index.php ----require/include--->tpl:index.php |----require/include-->header.php |----require/include-->footer.php
root index.php:
<?php function get_header(){ require('./tpl/header.php'); } function get_footer(){ require('./tpl/footer.php'); } $a = "I am a variable";
要求( './ TPL / index.php的');
TPL:index.php文件:
<?php get_header();//when I change require('./tpl/header.php'); variable $a can work!! echo '<br />'; echo 'I am tpl index.php'; echo $a; echo '<br />'; get_footer();//when I change require('./tpl/footer.php'); variable $a can work!!
TPL:header.php文件:
<?php echo 'I am header.php'; echo $a;//can not echo $a variable echo '<br/>';
TPL:footer.php:
<?php echo '<br />'; echo $a;//can not echo $a variable echo 'I am footer';
出于某种原因,当我使用函数来要求header.php和footer.php时,我的变量$ a没有得到回应。 如果我自己使用header.php或footer.php,它工作正常。 我不明白问题是什么。 您认为这里的问题是什么?
I have the following program Structure:
Root directory:-----index.php |-------TPL directory |-------------header.php |-------------index.php |-------------footer.php php file loading structure: Root directory:index.php ----require/include--->tpl:index.php |----require/include-->header.php |----require/include-->footer.php
Root index.php :
<?php function get_header(){ require('./tpl/header.php'); } function get_footer(){ require('./tpl/footer.php'); } $a = "I am a variable";
require('./tpl/index.php');
TPL:index.php:
<?php get_header();//when I change require('./tpl/header.php'); variable $a can work!! echo '<br />'; echo 'I am tpl index.php'; echo $a; echo '<br />'; get_footer();//when I change require('./tpl/footer.php'); variable $a can work!!
TPL:header.php:
<?php echo 'I am header.php'; echo $a;//can not echo $a variable echo '<br/>';
TPL:footer.php:
<?php echo '<br />'; echo $a;//can not echo $a variable echo 'I am footer';
For some reason when I used function to require header.php and footer.php my variable $a doesn't get echoed. It works fine if I use header.php or footer.php on its own. I do not understand what the problem is. What do you think is the issue here?
原文:https://stackoverflow.com/questions/16883839
最满意答案
如“ 如何使用滚动窗格”中所示 ,您可以使用组件的
scrollRectToVisible()
方法滚动到任意Rectangle
。 这里有一个例子。附录:作为一个
Container
,即使JPanel
具有相当多的嵌套内容,它也是相当可替代的。 在给定级别交换内容的一种可靠方法是通过CardLayout
, 此处和此处显示 。I solved the problem by using the JScrollbar method
setValues()
, which allows me to set at the same time the maximum, minimum, value and extent of the scrollbar. By setting the maximum and minimum to the values I want, the scrollbar behaves as I wanted/expected.The problem was that I was only setting maximum and minimum values (
setMaximum
,setMinimum
), and since there is a strict policy at the model that minimum <= value <= value+extent <= maximum, that estrategy did not work.
相关问答
更多-
如何始终显示滚动条(How to always show scrollbar)[2023-04-23]
截至目前,最好的方法是在xml中使用android:fadeScrollbars="false" ,相当于ScrollView.setScrollbarFadingEnabled(false); 在java代码中。 As of now the best way is to use android:fadeScrollbars="false" in xml which is equivalent to ScrollView.setScrollbarFadingEnabled(false); in java c ... -
你可以,但它不会是完美的。 复制此帖子中的代码: // Used like $('#my-id').hasScrollbar(); jQuery.fn.hasScrollbar = function() { var scrollHeight = this.get(0).scrollHeight; //safari's scrollHeight includes padding if ($.browser.safari) scrollHeight -= parseInt(this.css('pad ...
-
基础画布外滚动条和内容显示,具有广泛的主要内容(Foundation off-canvas scrollbar and content display with wide primary content)[2023-07-22]
添加overflow:auto; 对于css中的类.wrap并删除style="overflow-x:scroll;overflow-y:auto;" 来自html中的article标签。 我希望这有帮助。 Add overflow:auto; for the class .wrap in css and remove style="overflow-x:scroll;overflow-y:auto;" from the article tag in html. I hope this helps. -
如“ 如何使用滚动窗格”中所示 ,您可以使用组件的scrollRectToVisible()方法滚动到任意Rectangle 。 这里有一个例子。 附录:作为一个Container ,即使JPanel具有相当多的嵌套内容,它也是相当可替代的。 在给定级别交换内容的一种可靠方法是通过CardLayout , 此处和此处显示 。 I solved the problem by using the JScrollbar method setValues(), which allows me to set at t ...
-
我怎样才能确保一个网页打开与中间的滚动条(How can I make sure that a web-page opens up with scrollbar in the middle)[2023-06-03]
评论后更新如果主体的宽度不超过浏览器的视口: 在元素内滚动 : var elem = document.getElementById("container"); //div#container var elemWidth = elem.scrollWidth; var elemVisibleWidth = elem.offsetWidth; elem.scrollLeft = (elemWidth - elemVisibleWidth) / 2; 使用此代码垂直和水平居中页面(另请参阅: 本答案 ): ... -
您可以使用以下css代码调整iframe或任何元素的滚动条: iframe{ width:500px; height: 500px; overflow-x: hidden; overflow-y: scroll } I actually managed to resolve this issue myself using this approach with jQuery. $('testIframe').on('load', function(){ resizeIframe(this); ...
-
我用mcustomscrollbar实现了我想要的结果。 但是我花了一段时间才弄清楚如何在一个反应项目中使用它,我在这里解释了: Reactjs:带有reactjs的jQuery自定义内容滚动条 I achieved the results I want with mcustomscrollbar. But it took me a while to figure out how to use it within a react project, which I explained here: Reactj ...
-
我知道这是一个老问题,但是你的脚本帮我处理了固定的div。 在我的情况下,我有100%宽度固定标头。 一切正常,在启动脚本后,固定div中的一些元素仍然改变了位置。 所以,在你的脚本中我包含了这个: $('.header').css({ 'width': 'calc(100% - ' + margin+ 'px)' }); 关闭脚本后: $('.header').css('width','100%'); 正如我之前所说,在我的情况下,这工作得很好。 完整脚本如下所示: 点击: var width = $ ...
-
终于找到了一个解决方案后,我的头撞墙再过几个小时:似乎问题是由于SharePoint仍然在加载其内容(来自'sp.js'),并且因为时髦的东西它设置滚动条,我的脚本驱动的更改必须在SP滚动条完全初始化之前应用。 所以这是必须做的事情: $(document).ready(function(){ ExecuteOrDelayUntilScriptLoaded(runAfterSharePointIsDoneBeingStupid, 'sp.js'); }); function runAfterSha ...
-
滚动条不滚动(Scrollbar not scrolling)[2022-02-05]
滚动窗格的视图没有任何附加内容,因此没有任何内容可以滚动... 您需要使用scrollPane.setViewportView(...);等内容为滚动提供组件视图scrollPane.setViewportView(...); 您可能需要查看如何使用滚动窗格获取更多详细信息 代码中有很多东西让我担心...... GUI环境中的Thread.sleep总是令人担忧,因为这实际上可能会导致应用程序无响应。 出于同样的原因使用无限循环。 使用KeyListener只是执行ActionListener的相同功能 您 ...