CodeIgniter Forums
Database seeder with namespaces - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Database seeder with namespaces (/showthread.php?tid=81740)



Database seeder with namespaces - XMadMax - 04-21-2022

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


RE: Database seeder with namespaces - kenjis - 04-21-2022

See https://codeigniter4.github.io/userguide/dbmgmt/seeds.html#command-line-seeding

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


RE: Database seeder with namespaces - datamweb - 04-21-2022

(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



RE: Database seeder with namespaces - XMadMax - 05-11-2022

Thanks, this worked !!