CodeIgniter Forums
Controller not found when using namespaced modules - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Controller not found when using namespaced modules (/showthread.php?tid=67427)



Controller not found when using namespaced modules - baselbj - 02-21-2017

Hi;

I new to the psr4 world and I am trying to test Modules in CodeIgniter 4 I did the following:

1) Create folder Modules with the following structure:

application
Modules
..... Blog
.......... Controllers
............... BlogController.php
.......... Models
.......... Views
............... welcome_message.php

2) update application/Config/Autoload.php $psr4:

$psr4 = [
  'Config'                     => APPPATH.'Config',
  APP_NAMESPACE                => APPPATH,         // For custom namespace
  'App'                        => APPPATH,         // To ensure filters, etc still found
  'Modules'                    => APPPATH.'../Modules'
];


3) add the routes: $routes->add('blog', 'Modules\Blog\Controllers\BlogController::index');

4) The Content of BlogController.php

<?php
namespace Modules\Blog;
use CodeIgniter\Controller;

class BlogController extends Controller
{
   public function index()
   {

       return view('welcome_message');
   }

   //--------------------------------------------------------------------

}
 

5) when trying to open http://example.com/blog it returns: 404 - File Not Found.

6) I tried debugging the code line by    class_exists($this->controller, true) in CodeIgniter.php line 681 returns false.

Can any one help?


RE: Controller not found when using namespaced modules - InsiteFX - 02-21-2017

Modules in CodeIgniter 4


RE: Controller not found when using namespaced modules - baselbj - 02-21-2017

(02-21-2017, 08:10 AM)InsiteFX Wrote: Modules in CodeIgniter 4

I am using this but returned :
404 - File Not Found


RE: Controller not found when using namespaced modules - baselbj - 02-21-2017

After about 8 hours of debugging I found the issue, the name space should be defined like this:

 namespace Modules\Blog\Controllers;