PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 8, 2022

[FIXED] How to make propel build models with namespaces in the right directory?

 February 08, 2022     autoload, composer-php, namespaces, php, propel     No comments   

Issue

Default directory for my classes is: app/

Composer autoload config is:

{
    "autoload": {
        "psr-4": { "App\\": "app/" }
    }
}

On propel's schema.xml my namespace is "App\Models"

<database name="default" defaultIdMethod="native"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd"
          namespace="App\Models"
        >
    <table name="user">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="email" type="varchar" size="255" required="true"/>
        <column name="password" type="varchar" size="60" required="true"/>
        <column name="country_id" type="integer" required="true"/>
        <column name="timezone" type="varchar" size="50" required="true"/>
        <foreign-key foreignTable="country">
            <reference local="country_id" foreign="id"/>
        </foreign-key>
    </table>

    <table name="country">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="name" type="varchar" size="128" required="true"/>
    </table>
</database>

My propel.php.dist is:

<?php
return [
    'propel' => [
        'paths' => [
            // The directory where Propel expects to find your `schema.xml` file.
            'schemaDir' => 'database/schemas',

            // The directory where Propel should output generated object model classes.
            'phpDir' => 'app/Models'
        ]
    ]
];

When I execute vendor/bin/propel model:build the resulting structure is like this:

/app/
|___Models/
    |___App/
        |___Models/
            |___Base/
            |___Map/
            |___Country.php
            |___CountryQuery.php
            |___User.php
            |___UserQuery.php

I need the structure to be like this:

/app/
|___Models/
    |___Base/
    |___Map/
    |___Country.php
    |___CountryQuery.php
    |___User.php
    |___UserQuery.php

I tried every combination in this manual: Database Attributes

Is there a different way to approach this?

Thanks in advance.


Solution

The configuration specified in the question looks correct, except for one thing that is missing, which made it work in my case: set namespaceAutoPackage to false. In the case of the question's php configuration file, that looks like this:

<?php
return [
    'propel' => [
        'paths' => [
            // The directory where Propel expects to find your `schema.xml` file.
            'schemaDir' => 'database/schemas',

            // The directory where Propel should output generated object model classes.
            'phpDir' => 'app/Models'
        ],
        'generator' => [
            'namespaceAutoPackage' => 'false'
        ]
    ]
];


Answered By - RayOnAir
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing