在PHP中使用Spot ORM时出错

问题描述 投票:0回答:1

我正在使用Spot ORM(http://phpdatamapper.com)。问题:代码中途终止。关于如何使框架转储错误以进行调试的文档很少。代码在这里:

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',它仍然是一样的。

php orm
1个回答
0
投票

你有一个启动器的双名称空间声明,所以Post实际上是Config \ Post not Entity \ Post。

<?php
namespace Entity;
namespace Config;

class Post { }

$x = new Post();

echo "Class is: ", get_class($x);

?>

Class is: Config\Post
© www.soinside.com 2019 - 2024. All rights reserved.