【发布时间】:2016-09-22 03:33:10
【问题描述】:
我真的是 symfony 的新手,但我是一名漫长的开发者。现在我决定看一下 symfony,但由于它是新事物,问题不远:)
我想在我的项目中包含一个类。每次我创建类的实例时
$fw = new FloydWarshall($graph, $nodes);
我会收到内部错误 500。
我做错了什么?
结构:
app/
...
bin/
...
src/AppBundle/
Controller/MyController.php
Entity/
...
Model/
fw.class.php
Reposetory/
...
var/
...
vendor/
...
web/
...
所以在我的班级中,命名空间看起来像
namespace AppBundle\Controller;
use AppBundle\Entity\lpNodes;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use AppBundle\Model\FloydWarshall;
....
在我的 fw.class.php 中,标题看起来像:
<?php
/**
* @package FloydWarshall
* @author Janne Mikkonen <janne dot mikkonen at julmajanne dot com>
* @date $Date: 2013/03/23 05:10:48 $
* @version $Revision: 1.1.1 $
* @license GNU General Public License, version 2 http://www.opensource.org/licenses/GPL-2.0
**/
namespace AppBundle\Model;
class FloydWarshall {
FloydWarshall 的构造函数:
/**
* Constructor
* @param array $graph Graph matrice.
* @param array $nodenames Node names as an array.
*/
public function __construct($graph, $nodenames='') {
$this->weights = $graph;
$this->nodes = count($this->weights);
if ( ! empty($nodenames) && $this->nodes == count($nodenames) ) {
$this->nodenames = $nodenames;
}
$this->__floydwarshall();
}
【问题讨论】:
-
FloydWarshall类的__construct方法是什么样的?猜测是因为该文件没有使用 PSR-4 兼容的文件名 - 它应该被称为FloydWarshall.php而不是fw.class.php。然而,Symfony 应该会为您提供一些非常好的错误报告,这些报告会指出您正确的问题——您使用的是调试(即开发)环境吗? -
我会在 ajax 请求中收到此错误,因此 browserconsole 中没有错误......只有上述描述。
-
打开错误报告..
ini_set('display_errors', 'On'); error_reporting(E_ALL).. 500 错误基本上说.. 你真的搞砸了一些东西.. -
@Blowski Omg,我猜你只是用那个评论把它钉住了^^
-
你应该将@Blowski 的答案标记为正确的答案!