我有這樣的錯誤(在硅石2.0):UndefinedFunctionException試圖調用從名稱空間函數XXX XXX
UndefinedFunctionException在app.php線88:嘗試從名稱空間 「SocialWall \控制器」 調用函數 「postIndexArticle」 。
in app.php line 88
at {closure}(object(Application)) in Container.php line 113
at Container->offsetGet('home.controller') in CallbackResolver.php line 55
at CallbackResolver->convertCallback('home.controller') in ServiceControllerResolver.php line 50
at ServiceControllerResolver->getController(object(Request)) in HttpKernel.php line 136
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 68
at HttpKernel->handle(object(Request), '1', true) in Application.php line 496
at Application->handle(object(Request)) in Application.php line 477
at Application->run() in index.php line 17
我app.php
<?php
use SocialWall\Controller;
$app['home.controller'] = function($app) {
return SocialWall\Controller\postIndexArticle($app);
};
我route.php
<?php
// Home page
$app->get('/', 'home.controller')->bind('home');
HomeController.php
<?php
namespace SocialWall\Controller;
use Silex\Application;
use SocialWall\DAO\ArticleDAO;
function postIndexArticle(Application $app) {
return function() use ($app) {
return new $app['twig']->render('index.html.twig', array('articles' => $app['dao.article']->findAll()));
};
}
我需要幫助!
現在好了:我剛剛添加了「require_once __DIR __。」/ ../src/Controller/HomeController.php';「在我的index.php!並刪除」新「作爲你寫的控制器的回報 –
這就是爲什麼使用這種方法感到腥我:(:(需要require_once意味着返回以前自動加載很好請使用它 – seblucas
你說可以調用控制器是一個偉大的方法,如果使用惠特Autoload? –