私は理解できない問題がありますPHPクラスメソッドがxmlが正しく動作しないようにしています
私はクラスからWebサービスを作成しようとしています。 私はコントローラクラス内のいくつかの関数からxmlをエコーしようとしましたが、それはうまくいきませんでした。 それで、xmlを動かした場所に移動しました。
これは、ローダー関数が呼び出される前に配置したことを意味します。それはまだ動作します。ローダー関数の呼び出しの下にxmlを置くと、もう機能しません。 このように、ローダ関数は何らかの理由で動作していません。
私は例としてthis mvc modelを使用しました。 Sofarはすべて機能しましたが、現在は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を正しく設定しましたか? –
この設定では出力が得られます。 load()の下に、 私はXMLが届かないと思う。 私はそれをテストするセカンダリサイトを持っています。 私はエラー報告について見なければなりませんが、通常はエラーが表示されます、mayby、私はそれらをすべて見ませんか? – Richard