• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using and namespacing 'modules'

#1
UPDATE - 2020-04-20

I changed App\Config\Autoload.php to:

PHP Code:
<?php namespace Config;

require_once 
SYSTEMPATH 'Config/AutoloadConfig.php';

/**
 * -------------------------------------------------------------------
 * AUTO-LOADER
 * -------------------------------------------------------------------
 * This file defines the namespaces and class maps so the Autoloader
 * can find the files as needed.
 */
class Autoload extends \CodeIgniter\Config\AutoloadConfig
{
    public 
$psr4 = ['Start'  => APPPATH 'Modules/Start']; 

Added a route for the start module in App\Config\Routes.php:

PHP Code:
// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/''Home::index');
$routes->add('start''\App\Modules\Start\Controllers\Start'); 
 and updated App\Modules\Start\Controllers\Start.php:

PHP Code:
<?php
namespace App\Modules\Start\Controllers;
//namespace Start\Controllers;

use App\Controllers\BaseController;

class 
Start extends BaseController
{

    public function index()
    {
        return view('../Modules/Start/Views/start/index');
    }


    public function foo()
    {
        return view(''../Modules/Start/Views/start/foo');
    }


When I open http://localhost/ci4-test/start --> Bingo! It works
But when I open  http://localhost/ci4-test/start/foo: 404 - 'Controller or its method is not found: App\Controllers\Start::foo'

Is there something wrong in my routing file?

Thanks for any help or suggestion!



_____________

Yesterday, I was playing around with namespaces in a test application but it won't work out...

I created a subfolder 'Start' within  'App\Modules' (namespaced as 'Mine' in autoloader.php - see lower)
[Image: 0?ui=2&ik=fe539f4545&attid=0.1&permmsgid..._k92l7fk00]
In namespaced the controller and added the namespace to the autoloader:
[Image: 0?ui=2&ik=fe539f4545&attid=0.2&permmsgid..._k92lft991]
But it looks like the regular App\Controllers\ route is still followed...
[Image: 0?ui=2&ik=fe539f4545&attid=0.3&permmsgid..._k92lhhg72]
Any idea what I'm doing wrong?

Many tanks in advance!

Zeff
Reply


Messages In This Thread
Using and namespacing 'modules' - by Zeff - 04-16-2020, 06:01 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.