【问题标题】:php class method is preventing xml from working correctlyphp 类方法阻止 xml 正常工作
【发布时间】:2010-11-14 02:56:34
【问题描述】:

我有一个我无法理解的问题

我正在尝试让我的网络服务在课堂上工作。 我尝试从控制器类中的某个函数中回显 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?
  • 我在这个设置中得到了输出,是的。在加载()下面,不,我认为 xml 只是没有到达。我有一个辅助站点来测试它。我必须查看错误报告,但通常我确实会看到错误,也许我没有看到所有错误?

标签: php xml model-view-controller oop class


【解决方案1】:

Err - 不是因为“exit()”调用吗?我可能错了。

【讨论】:

  • 谢谢,没有影响,只是为了测试。这里唯一重要的是,如果我将它放在 loader() 下,它就不再起作用了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多