我試圖讓所選語言出現在功能buildMenu()
的鏈接中。使用具有屬性的靜態類php
我想使用它作爲一個靜態函數,所以我可以在我的頭模板中調用它。如果我在init()
函數中調用該函數,那麼它可以正常工作,但是,當我嘗試將它用作靜態函數時,什麼都不起作用。我已經嘗試了我所知道的一切,所以看起來我對PHP的知識就此結束:)
你們有沒有得到任何提示?提前致謝!
class bootstrap {
static public $lang;
static public $class;
static public $method;
public function init(){
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
//Set values on startup
if($url[0] == NULL) {$url[0] = 'nl';}
if($url[1] == NULL) {$url[1] = 'index';}
if(isset($url[0])) {$this->lang = $url[0];}
if(isset($url[1])) {$this->class = $url[1];}
if(isset($url[2])) {$this->method = $url[2];}
$this->loadClass();
}
public function loadClass(){
$filename = 'libs/' . $this->class . '.php';
if(file_exists($filename)){
$newController = new $this->class($this->lang, $this->class, $this->method);
$newView = new view($this->lang, $this->class, $this->method);
} else {
$newclass = new error($this->lang, $this->class, $this->method);
}
}
public function buildMenu(){
echo '<li><a href="http://localhost/testing/' . $this->lang . '/foto">Foto</a></li>';
}
/*
* Set paths
*/
public static function root(){
echo "http://localhost/testing/";
}
}
'自:: $ LANG,自:: $類,...' – elclanrs