Welcome Guest, Not a member yet? Register   Sign In
Database seeder with namespaces
#1

(This post was last modified: 04-21-2022, 12:31 AM by XMadMax.)

Hello, I developed a CI4 Modular structure, all works Ok, but I have a problem with Seeder.

Migrations (php spark migrate) works ok, because the migrate program uses namespaces, but "php spark db: seed" only uses filesPath config, instead of those path defined in command line (php spark db: seed Users/MySeeder.php)

As suggestion, system/Comands/Database/Seed.php would share $params with Seeder.php to be able to use namespaces.

If, as the example proposed, $params contains 'Users/Database/Seeds/MySeeder.php', in the constructor, $this->seedPath would to be set properly if first part of route is a defined in autoload.php:$psr4

Thanks,

Xavier
Reply
#2

(This post was last modified: 04-21-2022, 01:27 AM by kenjis.)

See https://codeigniter4.github.io/userguide...ne-seeding

`spark db: seed` takes Seeder classname, not Seeder file path.
Reply
#3

(04-21-2022, 12:30 AM)XMadMax Wrote: Hello, I developed a CI4 Modular structure, all works Ok, but I have a problem with Seeder.

Migrations (php spark migrate) works ok, because the migrate program uses namespaces, but "php spark db: seed" only uses filesPath config, instead of those path defined in command line (php spark db: seed Users/MySeeder.php)

As suggestion, system/Comands/Database/Seed.php would share $params with Seeder.php to be able to use namespaces.

If, as the example proposed, $params contains 'Users/Database/Seeds/MySeeder.php', in the constructor, $this->seedPath would to be set properly if first part of route is a defined in autoload.php:$psr4

Thanks,

Xavier

Here is an example:

Code:
public $psr4 = [
        'MyNameSpace'         => APPPATH . 'ThirdParty\MyPackag',
    ];

Code:
php spark db:seed MyNameSpace\Database\Seeds\UrgenciesSampel

NOTE:
UrgenciesSampel IS HERE :

Code:
app\ThirdParty\MyPackag\Database\Seeds\UrgenciesSampel.php
Reply
#4

Thanks, this worked !!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB