duai8153
2014-11-02 20:19
浏览 73
已采纳

Silex,没找到上课

I want access of a function in my controller "ItemController". I always have the error; Fatal error: Class 'Iso\Controller\ItemController' not found ...

testsilex / Silex

 - app
 - composer.json
 - src
        - routes.php
        - Iso
            - Controller
                  - ItemController.php

 - vendor
 - web
       - index.php

I have an index.php file in Silex/Web

ini_set('display_errors', 1);
require_once __DIR__.'/../vendor/autoload.php';
$app = require __DIR__.'/../app/app.php';
require __DIR__.'/../src/routes.php';
$app['debug'] = true;
$app->run();

My itemcontroller looks like:

<?php
namespace Iso\Controller;
use Silex\Application;
class ItemController
{
    public function indexAction(Request $request, Application $app)
    {
           echo "it works";
    }
}

My routes.php looks like:

$app->mount('/testsilex/silex/test', new Iso\Controller\ItemController());

My composer.json i added next line:

"autoload": {
        "psr-0": {"Iso": "src/"}
    }

Does anyone know why my class is not found? It will be a small mistake but i can't find it. Thanks :)

图片转代码服务由CSDN问答提供 功能建议

我想在我的控制器“ItemController”中访问一个函数。 我总是有错误; Fatal错误:未找到类'Iso \ Controller \ ItemController'

testsilex / Silex

   -  app 
  -  composer.json 
  -  src 
  -  routes.php 
  -  Iso 
  -  Controller 
  -  ItemController.php 
 
  -  vendor 
  -  web 
  -  index.php 
  <  / pre> 
 
 

我在Silex / Web中有一个index.php文件

  ini_set('display_errors',1); 
require_once __DIR __。'/  ../vendor/autoload.php';
$app = require __DIR __。'/ .. / app / app.php'; 
require __DIR __。'/ .. / src / routes.php'; 
 $ app  ['debug'] = true; 
 $ app-&gt; run(); 
   
 
 

我的itemcontroller如下所示: < pre> &lt;?php namespace Iso \ Controller; use Silex \ Application; class ItemController { public function indexAction(Request $ request,Application $ app) { echo“它的工作原理 “; } }

我的routes.php如下所示:

  $ app-&gt  ; mount('/ testsilex / silex / test',new Iso \ Controller \ ItemController()); 
   
 
 

我的composer.json我添加了下一行:

 “autoload”:{
“psr-0”:{“Iso”:“src /”} 
}  
   
 
 

有谁知道为什么找不到我的班级? 这将是一个小错误,但我找不到它。 谢谢:)

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题