Welcome Guest, Not a member yet? Register   Sign In
Using and namespacing 'modules'
#1

(This post was last modified: 04-20-2020, 02:36 AM by Zeff.)

[font=Roboto, RobotoDraft, Helvetica, Arial, sans-serif][font=Arial, Helvetica, sans-serif][font=arial, sans-serif]UPDATE - 2020-04-20[/font][/font][/font]

[font=Roboto, RobotoDraft, Helvetica, Arial, sans-serif][font=Arial, Helvetica, sans-serif][font=arial, sans-serif]I changed App\Config\Autoload.php to:[/font][/font][/font]

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']; 

[font=Roboto, RobotoDraft, Helvetica, Arial, sans-serif][font=Arial, Helvetica, sans-serif][font=arial, sans-serif]Added a route for the start module in App\Config\Routes.php:[/font][/font][/font]

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'); 
[font=Roboto, RobotoDraft, Helvetica, Arial, sans-serif][font=Arial, Helvetica, sans-serif][font=arial, sans-serif] and updated App\Modules\Start\Controllers\Start.php:[/font][/font][/font]

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');
    }


[font=Roboto, RobotoDraft, Helvetica, Arial, sans-serif][font=Arial, Helvetica, sans-serif][font=arial, sans-serif]When I open http://localhost/ci4-test/start --> Bingo! It works[/font][/font][/font]
[font=Roboto, RobotoDraft, Helvetica, Arial, sans-serif][font=Arial, Helvetica, sans-serif][font=arial, sans-serif]But when I open [font=arial, sans-serif] http://localhost/ci4-test/start/foo: 404 - 'Controller or its method is not found: App\Controllers\Start::foo'[/font][/font][/font][/font]

[font=Roboto, RobotoDraft, Helvetica, Arial, sans-serif][font=Arial, Helvetica, sans-serif][font=arial, sans-serif][font=arial, sans-serif]Is there something wrong in my routing file?[/font][/font][/font][/font]

Thanks for any help or suggestion!



_____________

[font=Roboto, RobotoDraft, Helvetica, Arial, sans-serif][font=Arial, Helvetica, sans-serif][font=arial, sans-serif]Yesterday, I was playing around with namespaces in a test application but it won't work out...[/font][/font][/font]

[font=arial, sans-serif]I created a subfolder 'Start' within  'App\Modules' (namespaced as 'Mine' in autoloader.php - see lower)[/font]
[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




Theme © iAndrew 2016 - Forum software by © MyBB