在PHP中使用Spot ORM时出错
我正在使用Spot-ORM()。 问题是:代码中途终止。 关于如何让框架转储错误以进行调试的文档很少。代码如下:在PHP中使用Spot ORM时出错,php,orm,Php,Orm,我正在使用Spot-ORM()。 问题是:代码中途终止。 关于如何让框架转储错误以进行调试的文档很少。代码如下: namespace Entity; namespace Config; require 'vendor/autoload.php'; echo "hello"; set_time_limit(0); error_reporting(E_ALL); class Post extends \Spot\Entity { protected static $table =
namespace Entity;
namespace Config;
require 'vendor/autoload.php';
echo "hello";
set_time_limit(0);
error_reporting(E_ALL);
class Post extends \Spot\Entity
{
protected static $table = 'posts';
public static function fields()
{
return [
'id' => ['type' => 'integer', 'primary' => true, 'autoincrement' => true],
'title' => ['type' => 'string', 'required' => true],
'body' => ['type' => 'text', 'required' => true],
'status' => ['type' => 'integer', 'default' => 0, 'index' => true],
'author_id' => ['type' => 'integer', 'required' => true],
'date_created' => ['type' => 'datetime', 'value' => new \DateTime()]
];
}
}
class Url extends \Spot\Entity
{
protected static $table = 'urls';
public static function fields()
{
return [
'id' => ['type' => 'integer', 'primary' => true, 'autoincrement' => true],
'domain' => ['type' => 'text'],
'url' => ['type' => 'text', 'required' => false],
'classification1' => ['type' => 'text', 'required' => false],
'section' => ['type' => 'string', 'required' => false],
'status' => ['type' => 'text'],
/* 'author_id' => ['type' => 'integer', 'required' => true],
'date_created' => ['type' => 'datetime', 'value' => new \DateTime()]
];
}
}
$cfg = new \Spot\Config();
$spot = new \Spot\Locator($cfg);
$cfg->addConnection('mysql', [
'dbname' => 'sotereading',
'user' => 'root',
'password' => 'root',
'host' => 'localhost',
'driver' => 'pdo_mysql',
]);
echo "hello";
/* this line has a problem */
$mapper = $spot->mapper('Entity\Post');
echo "hello";
$mapper->migrate();
echo "hello";
我使用了简单的“echo”语句来缩小问题所在行的范围,并找到了问题所在(请参见上面代码中/**/中的注释)。为什么会有这样的问题?无论我使用的是'Entity\Post'还是'Entity\Url',都是一样的。您有一个双名称空间声明,因此Post实际上是Config\Post而不是Entity\Post
<?php
namespace Entity;
namespace Config;
class Post { }
$x = new Post();
echo "Class is: ", get_class($x);
?>
Class is: Config\Post
类是:Config\Post