Grazio lo avevo già visto ma la mia situazione è un po' strana perchè __DIR__ funziona in un caso ma non in un altroOriginariamente inviato da skjobax
Leggi questo, può essere d'aiuto
http://php.net/manual/en/language.co...predefined.php
E comunque, meglio un semplice link href che complicarsi la vita secondo me...
Ma se lo fai per protezione...
nel sorgente html che è stato generato viene indicato questo url /home/pagliasn/public_html/projects/CloudCoding/template/style.css però se ci clicco sopra mi manda a sito.net/home/pagliasn/public_html/projects/CloudCoding/template/style.css il che è sbagliato.
Ti posto qualche file per capire meglio.
Nel cartella del progetto ho:
index.php
config.php
/template
style.css
header.php
Ho omesso alcuni file che non dovrebbero interessarci. Allora index.php non fa altro che richiamare config.php che è questo:
codice:<?php class CloudCoding{ public $project_name = "CloudCoding"; public $project_url = "http://localhost/CloudCoding/"; public $root; public $template_folder = "/template/"; public $pages_folder = "/pages/"; public $css_path; public function __construct(){ $this->root = dirname(__FILE__); $this->css_path = $this->root.$this->template_folder."style.css"; } public function getPage(){ include('./config/page-list.php'); if(isset($_GET['page'])){ $page = $_GET['page']; if(file_exists($this->root.$this->pages_folder.$page.'.php')){ $page_title = $page_list[$page]['title']; $title = $page_title." - ".$this->project_name; require($this->root.$this->template_folder."header.php"); require($this->root.$this->pages_folder.$page.'.php'); require($this->root.$this->template_folder."footer.php"); }else{ $page_title = $page_list['not-found']['title']; $title = $page_title." - ".$this->project_name; require($this->root.$this->template_folder."header.php"); require($this->root.$this->pages_folder.'not-found.php'); require($this->root.$this->template_folder."footer.php"); } }elseif(!isset($_GET['page'])){ $page_title = $page_list['home']['title']; $title = $page_title." - ".$this->project_name; require($this->root.$this->template_folder."header.php"); require($this->root.$this->pages_folder.'home.php'); require($this->root.$this->template_folder."footer.php"); } } } ?>
$root è ottenuto con la funzione __DIR__ poi c'è $css_path che è ottenuto con $root (relativo a config.php) + /template/style.css
Ora config.php include header.php in /template e da header.php dovrei richiamare style.css che si trova nella stessa cartella ma che invece richiama site.net/root/template/style.css come scritto sopra.
La cosa strana è che se con lo stesso modo includo un file direttamente da config.php questo viene incluso correttamente come in questo caso:
Codice:
$this->root.$this->template_folder."header.php"