0

別のファイルから関数を呼び出すのに問題があります。require_once( $library_path .'Main/SystemUtility.class.php');関数を呼び出すよりも一番上に置いてみましたが、機能していません。関数名は、SystemUtility.class.php に立つ loadController です。

<?php
    class Main {
        function Main() {
        }

        function getInstance() {
            static $instance = null;

            if (null === $instance) {
                $instance = new Main();
            }

            return $instance;
        }

        function dispatch($args = '') {
            $page = '';
            $params = '';
            $controller = 'index';
            $action = 'index';
            $count = 0;

            if ($args != '') {
                $page = $args;
            } else {
                if (isset( $_GET['page'] )) {
                    $page = $_GET['page'];
                } else {
                    if (!isset( $_GET['page'] )) {
                        $page = 'index/index';
                    }
                }
            }


            if ($page == 'index.php') {
                $page = '';
            }

            $params = explode( '/', $page );
            $count = count( $params );

            if (0 < $count) {
                if ($params[0] != '') {
                    $controller = $params[0];
                }
            }


            if (1 < $count) {
                if ($params[1] != '') {
                    $action = $params[1];
                }
            }

            $action = str_replace( '-', '_', $action );
            $controller = str_replace( '-', '_', $controller );
            $valueparams = array(  );
            $i = 0;

            while ($i < $count - 2) {
                $valueparams[$i] = $params[$i + 2];
                ++$i;
            }

            include('script.inc.php');
            require_once($library_path.'Main/NesoteController.class.php');
            loadController($controller.'Controller');
            $controllerInstance = createControllerInstance( $controller . 'Controller' );
            $actionexists = 1;
            $actionMethod = $action . 'Action';

            if (!method_exists( $controllerInstance, $actionMethod )) {
                $actionexists = 0;

                if (!file_exists( '' . $view_path . $controller . '/' . $action . '.tpl.html' )) {
                    $err_msg = '<br><strong>Error: </strong>Requested page was not found!';
                    $ini_error_status = ini_get( 'error_reporting' );

                    if ($ini_error_status != 0) {
                        $err_msg .= '' . '<br><strong>Details: </strong><strong>' . $action . '</strong> Action not found!';
                    }

                    loadErrorTemplate( $err_msg );
                    exit( 0 );
                }
            }
            if (strcasecmp( get_parent_class( $controllerInstance ), 'NesoteController' ) != 0) {
                $ini_error_status = ini_get( 'error_reporting' );

                if ($ini_error_status != 0) {
                    echo '' . '<br><strong>Error: ' . $controller . 'Controller</strong> should extend NesoteController.';
                }

                exit( 0 );
            }

            $shownoviewerror = 0;

            if (!file_exists( '' . $view_path . $controller . '/' . $action . '.tpl.html' )) {
                $shownoviewerror = 1;
                loadTemplate( '' . $view_path . $controller . '/' . $action . '.tpl.html', '' );
            } else {
                loadTemplate( '' . $view_path . $controller . '/' . $action . '.tpl.html' );
            }

            arguments( $valueparams );

            if ($actionexists != 0) {
                $actionMethod(  );
            }


            if ($shownoviewerror == 1) {
                $ini_error_status = ini_get( 'error_reporting' );

                if ($ini_error_status != 0) {
                    echo '' . '<br><strong>Error: </strong> View file for the ' . $action . ' action, <strong>' . $view_path . $controller . '/' . $action . '.tpl.html</strong> does not exist.';
                }

                exit( 0 );
            }

            includePage( $controllerInstance );
        }
    }

    require_once( 'script.inc.php' );
    require_once( $library_path .'Main/SystemUtility.class.php');
?>
4

1 に答える 1

1

のインスタンスを作成し、そのSystemUtilityメソッドを呼び出す必要があります。

交換:

 include('script.inc.php');
 require_once($library_path.'Main/NesoteController.class.php');
 loadController($controller.'Controller');

と:

 require_once($library_path.'Main/SystemUtility.class.php');
 $sysUtil = new SystemUtility();
 $sysUtil->loadController($controller.'Controller');
于 2013-01-06T01:58:49.330 に答える