-
luckmoshy
Do Codeigniter before do you!
-
Posts: 248
Threads: 51
Joined: Nov 2020
Reputation:
7
12-22-2023, 08:13 PM
(This post was last modified: 12-22-2023, 08:31 PM by luckmoshy.)
Hi all I was taking a little bit of a look and found that in CI PSR4 autoloader, it does not work for more than two module autoloading as follows:
PHP Code: public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', //Here if both, only one work why??!! 'Admin\Editor' => ROOTPATH . 'Admin/Editor',//this is working 'Admin\User' => ROOTPATH . 'Admin/User',//not is not working ];
Above there are two namespaced modules and all work fine except I have to switch off one
like
PHP Code: public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', // 'Admin\Editor' => ROOTPATH . 'Admin/Editor', 'Admin\User' => ROOTPATH . 'Admin/User',//This will work because first one is off
];
and
PHP Code: public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', 'Admin\Editor' => ROOTPATH . 'Admin/Editor',//This will work fine because the second one is off // 'Admin\User' => ROOTPATH . 'Admin/User',
];
Why this or is there any priority like (route priority) should I use?
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals
-
kenjis
Administrator
-
Posts: 3,255
Threads: 90
Joined: Oct 2014
Reputation:
205
12-22-2023, 11:39 PM
(This post was last modified: 12-22-2023, 11:40 PM by kenjis.)
What does not work?
At least the following code works.
PHP Code: --- /dev/null +++ b/Foo/Editor/Config/Routes.php @@ -0,0 +1,10 @@ +<?php + +namespace Foo\Editor\Config; + +use CodeIgniter\Router\RouteCollection; + +/** + * @var RouteCollection $routes + */ +$routes->get('editor', [\Foo\Editor\Controllers\Home::class, 'index']);
--- /dev/null +++ b/Foo/Editor/Controllers/Home.php @@ -0,0 +1,13 @@ +<?php + +namespace Foo\Editor\Controllers; + +use App\Controllers\BaseController; + +class Home extends BaseController +{ + public function index() + { + return __METHOD__; + } +}
--- /dev/null +++ b/Foo/User/Config/Routes.php @@ -0,0 +1,10 @@ +<?php + +namespace Foo\User\Config; + +use CodeIgniter\Router\RouteCollection; + +/** + * @var RouteCollection $routes + */ +$routes->get('user', [\Foo\User\Controllers\Home::class, 'index']);
--- /dev/null +++ b/Foo/User/Controllers/Home.php @@ -0,0 +1,13 @@ +<?php + +namespace Foo\User\Controllers; + +use App\Controllers\BaseController; + +class Home extends BaseController +{ + public function index() + { + return __METHOD__; + } +}
--- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -46,6 +46,8 @@ class Autoload extends AutoloadConfig public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', + 'Foo\Editor' => ROOTPATH . 'Foo/Editor', + 'Foo\User' => ROOTPATH . 'Foo/User', ]; /**
Code: $ php spark routes
CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-12-23 06:38:23 UTC+00:00
+--------+--------+------+-------------------------------------+----------------+---------------+
| Method | Route | Name | Handler | Before Filters | After Filters |
+--------+--------+------+-------------------------------------+----------------+---------------+
| GET | / | » | \App\Controllers\Home::index | | toolbar |
| GET | editor | » | \Foo\Editor\Controllers\Home::index | | toolbar |
| GET | user | » | \Foo\User\Controllers\Home::index | | toolbar |
+--------+--------+------+-------------------------------------+----------------+---------------+
-
luckmoshy
Do Codeigniter before do you!
-
Posts: 248
Threads: 51
Joined: Nov 2020
Reputation:
7
12-23-2023, 02:02 AM
(This post was last modified: 12-23-2023, 02:28 AM by luckmoshy.)
Thank @ kenjis Every things are now okay but I don't know why if I use
PHP Code: <?php namespace Foo\User\Config;
$routes->group('user', ['namespace' => 'Foo\User\Controllers'], static function ($routes) { //$routes->match(['get', 'post'],'index', 'userHome::index'); does not work $routes->get('index', [\Foo\User\Controllers\userHome::class, 'index']); //This style work
});
I have used your fully qualified root namespace example and now about ten modules work fine !!!!
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals
|