php sınıf yöntemi düzgün çalışmasını xml engelliyor

1 Cevap php

Ben anlayamıyorum bir sorun var

I am trying to make my webservice work from a class. I try'd to echo the xml from some function in a controllerclass, but that diddn't work. So, I moved the xml around to a place where it did work.

That means that I placed it before the loader function is called. That's where it still works. If I place the xml underneath the call to the loader function it's not working anymore. Thus the loader function somehow is preventing it to work.

I used this mvc model as an example how to do it. Sofar it all worked, except for the xml implementation now.

Nerede başlar bu

<?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
?>

Bunun içinde yükleyici fonksiyonu ile yönlendirici sınıf

<?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';
    }
}
?>

teşekkürler, Richard

1 Cevap

Err - çünkü 'exit ()' çağırma değil mi? Ben yanlış olabilir.