0
我有一個問題,我不明白php類的方法是防止xml正常工作
我想讓我的web服務工作從一個類。 我試着從控制器類中的某個函數回顯xml,但沒有奏效。 所以,我將xml移到了它的工作地點。
這意味着我把它放在加載函數被調用之前。這就是它仍然有效的地方。如果我將xml放在對加載函數的調用下面,它就不再工作了。 因此,加載程序功能以某種方式阻止它的工作。
我用this mvc model爲例說明如何做。 沙發它一切工作,除了現在的xml實現。
這是它開始
<?php
include "registraties/includes/config.php";
include (MYSQL);
//WEBSERVICE SECTIE
/*** include de init.php file ***/
include 'includes/init.php';
/*** laad de router ***/
$registratie->router = new router($registratie);
/*** set het pad van de controller map ***/
$registratie->router->setPad ('controller');
/*** laad de template ***/
$registratie->template = new template($registratie);
$gebruikersnaam="kabouter";
header('Content-type: text/xml');
$status_code = 2;
$output= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$output.= "<response>\n";
$output.= "\t<status>$status_code</status>\n";
$output.= "\t<fout>$gebruikersnaam</fout>\n";
$output.= "</response>";
echo trim($output);
exit();
/*** laad de controller ***/
$registratie->router->loader();
// at this place the xml does not work
?>
這是它
<?php
class router {
/*
* @de registratie
*/
private $registratie;
/*
* @het pad naar de controller map
*/
private $pad;
private $args = array();
public $bestand;
public $controller;
public $actie;
function __construct($registratie) {
$this->registratie = $registratie;
}
/**
*
* @set controller directory pad
*
* @param string $pad
*
* @return void
*
*/
function setPad($pad) {
/*** check of map bestaat***/
if (is_dir($pad)){
/*** set het pad ***/
$this->pad = $pad;
}else{
throw new Exception ('Ongeldig controller pad: `' . $pad . '`');
}
}
/**
*
* @laad the controller
*
* @access public
*
* @return void
*
*/
public function loader(){
/*** check de route ***/
$this->getController();
/*** als het bestand niet bestaat ***/
if (is_readable($this->bestand) == false){
$this->bestand = $this->pad.'/error404.php';
$this->controller = 'error404';
}
/*** include de controller ***/
include $this->bestand;
/*** een nieuwe controller class instance ***/
$class = $this->controller . 'Controller';
$controller = new $class($this->registratie);
/*** check of actie is callable ***/
if (is_callable(array($controller, $this->actie)) == false){
$actie = 'index';
}else{
$actie = $this->actie;
}
/*** voer de actie uit ***/
$controller->$actie();
}
/**
*
* @get de controller
*
* @access private
*
* @return void
*
*/
private function getController() {
/*** get de route van de url ***/
$route = (empty($_GET['url'])) ? '' : $_GET['url'];
if (empty($route)){
$route = 'index';
}else{
/*** krijg de segmenten van de route ***/
$parts = explode('/', $route);
$this->controller = $parts[0];
if(isset($parts[1])){
$this->actie = $parts[1];
}
}
if (empty($this->controller)){
$this->controller = 'index';
}
/*** get actie ***/
if (empty($this->actie)){
$this->actie = 'index';
}
/*** set het bestands adres ***/
$this->bestand = $this->pad .'/'. $this->controller . 'Controller.php';
}
}
?>
感謝路由器類加載器功能,理查德
什麼意思是「不起作用」?任何輸出?你有沒有正確設置display_errors和error_reporting? – 2009-07-26 10:25:51
我在這個設置中得到輸出,是的。在加載()下面,沒有 我認爲xml只是沒有到達。 我有一個輔助站點來測試它。 我必須看到關於錯誤報告,但通常我會看到錯誤,mayby,我沒有看到它們全部? – Richard 2009-07-26 12:11:59