autoload |
i am playing with CI4 as well, and also developing in CI3.
In ci4, there is the application/controllers/X.php where i can define controller and call http://localhost/class/method/ and it works fine. now what I did is in the same folder where application lives, i created my folder called admin0 admin0 - Controllers - User.php - Models - Views - applicaiton - public - system - tests - user_guide_src - writable This is what User.php has: <?php namespace admin0\User; class User extends \CodeIgniter\Controller { public function ping() { echo "PONG PONG PONG !!!"; } } -- No matter what i tried, I could not make http://localhost/user/ping work : ![]() how do someone loads this psr4 in CI4 - in the above structure ? Thanks,
I managed to add this in route
$routes->add('user', 'admin0\User\Controllers\User::index'); $routes->add('user/ping', 'admin0\User\Controllers\User::ping'); $routes->add('user/test', 'admin0\User\Controllers\User::test'); i do not think that is the right way i think ?? (06-19-2018, 08:02 AM)admin0 Wrote: I managed to add this in route I recently ran into this, but your namespace is already enabled by default. However, you can add your own, where you need to use the module code (maybe it will suit you). The core element of the modules functionality comes from the PSR4 compatible autoloading that "CodeIgniter" uses. For example, in your case this could be: PHP Code: public $psr4 = [ PHP Code: <? namespace Admin0\User\Controllers; PHP Code: $routes->get('user', 'User::index'); Perhaps in this case there are more suitable implementation options, since I myself have just started trying CI4.
You need to add the Controllers folder to your name space.
And add the path to the psr-4 autoloader. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |