-2

我在 Symfony 中收到此错误我按照我不理解的链接尝试过。

数据库映射未初始化。请检查您的配置文件中包含的数据库加载器脚本。 有关如何解决此问题的信息,请访问 https://github.com/propelorm/Propel2/wiki/Exception-Target:-Loading-the-database 。

控制器:

    $content = new Content();
    
    $content->setTitle("Hello World");
    $content->setDescription("Welcome to the land of Chaos..");
    
    $comment = new Comment();
    $comment->setPost_comment("This is the Comment...");
    
    $content->addComment($comment);
    $content->save();

推进.yml

propel:
    database:
        connections:
            test_p:
                adapter:    mysql
                user:       "%env(DB_USER)%"
                password:   "%env(DB_PWD)%"
                dsn:        "mysql:host=%env(DB_HOST)%;dbname=%env(DB_NAME)%;charset=UTF8"

架构.xml

<database name="test_p" namespace="App\Model">
    <table name="category" idMethod="native" phpName="Category">
        <column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true"/>
        <column name="title" phpName="Title" type="VARCHAR" size="255" defaultValue="NULL" required="true"/>
    </table>

    <table name="content" idMethod="native" phpName="Content">
        <column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" />
        <column name="title" phpName="Title" type="VARCHAR" size="255" defaultValue="NULL" required="true" />
        <column name="description" phpName="Description" type="VARCHAR" size="255" defaultValue="NULL" required="true" />
    </table>
    
    <table name="comment" idMethod="native" phpName="Comment">
        <column name="id" phpName="Id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" /> 
        <column name="post_comment" phpName="Post_comment" type="VARCHAR" size="255" defaultValue="NULL" required="true"/>
        <column name="content_id" phpName="ContentId" type="INTEGER" required="true"/>
        <foreign-key foreignTable="content">
            <reference local="content_id" foreign="id" />
        </foreign-key>    
    </table>
</database>

加载数据库.php

$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();

$serviceContainer->initDatabaseMaps(array (
  'test_p' => 
  array (
    0 => '\\App\\Model\\Map\\CategoryTableMap',
    1 => '\\App\\Model\\Map\\CommentTableMap',
    2 => '\\App\\Model\\Map\\ContentTableMap',
  ),
));
4

0 回答 0