簡體   English   中英

范圍廣泛的php變量

[英]php variable with site wide scope

我正在使用Kirby CMS,並創建了一個小片段,該片段根據帖子的數量和日期限制了該帖子。 基本上是一種創建“自動發布”系統的方法。

$today = new DateTime("now"); //Declare today
$startdate = new DateTime("2013-09-12"); //Declare startdate
$interval = $startdate->diff($today); //Find the difference between startdate & today
$latest = $interval->format('%a'); //Declare $latest variable to be that interval, formatted as integer

因此,我需要一點點來創建$latest變量,然后可以使用它來控制顯示的帖子。

我的問題是,我不想在我擁有的每種不同類型的頁面模板上都更改$startdate ,因此我想以某種方式使其在整個網站范圍內。

我嘗試使用Kirby的snippet()函數將其作為代碼段,但這不起作用。 我猜想,在片段運行之后,必須將這些片段帶入頁面。

如何使我的代碼段適用於整個網站?

PHP沒有站點范圍的變量。 您能做的最好的事情就是將分配放在腳本中,例如site.php ,並使所有頁面都以require 'site.php';開頭require 'site.php'; 初始化這些變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM