2017-01-03 13 views
0

altorouterを使用してHomeコントローラのindex()メソッドを取得しようとしましたが、できませんでした。私はいくつかの場所を検索しましたが、私は助けを見つけることができませんでした。Altorouterでコントローラのメソッドを呼び出す

は、ここでのindex.php

<?php 

include 'system/startup.php'; 
include 'library/AltoRouter.php'; 

// Router 
$router = new AltoRouter(); 
// Change here before upload 
$router->setBasePath('/demo'); 
$router->map('GET|POST','/', 'home#index', 'home'); 

// match current request 
$match = $router->match(); 

if($match && is_callable($match['target'])) { 
    call_user_func_array($match['target'], $match['params']); 
} else { 
    // no route matched 
    header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); 
} 

カタログ>コントローラディレクトリ内のホームコントローラです。

<?php 
class home { 
    public function index() { 
     echo 'home'; 
    } 
} 

このaltorouterガイドを使用している人はいますか?

P.S.私はstartup.phpファイル(index.phpの上部に含まれています)にオートロード機能を持っています

+0

あなたのリクエストはどうなっていますか? –

+0

@hd、これは家にいるはずです....私のxamppでは "localhost/demo" –

答えて

0

これは古いスレッドですが、これはあなたを助けることができます。あなたは別の方法で一致リクエストが必要です:

<?php 

include 'system/startup.php'; 
include 'library/AltoRouter.php'; 

// Router 
$router = new AltoRouter(); 
$router->setBasePath('/demo'); 
$router->map('GET|POST','/', 'home#index', 'home'); 
$match = $router->match(); 

if ($match === false) { 
    // here you can handle 404 
} else { 
    list($controller, $action) = explode('#', $match['target']); 
    if (is_callable(array($controller, $action))) { 
     call_user_func_array(array($controller,$action), array($match['params'])); 
    } else { 
     // here your routes are wrong. 
     // Throw an exception in debug, send a 500 error in production 
    } 
} 
関連する問題