Welcome Guest, Not a member yet? Register   Sign In
autoload
#3

(This post was last modified: 06-21-2018, 12:06 AM by Nome.)

(06-19-2018, 08:02 AM)admin0 Wrote: 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 ??

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 = [
 
   'Admin0\User' => APPPATH.'admin0/User' //Change the PATH depending on the location of the directory
]; 
in Controller User.php
PHP Code:
<? namespace Admin0\User\Controllers;

use Admin0\User\Models\UserModel;
use ...

class User extends \CodeIgniter\Controller
{
    public function index() { echo 'Say hi!'; }
}

... 
in Routes.php
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.
Reply


Messages In This Thread
autoload - by admin0 - 06-19-2018, 07:46 AM
RE: autoload - by admin0 - 06-19-2018, 08:02 AM
RE: autoload - by Nome - 06-21-2018, 12:01 AM
RE: autoload - by InsiteFX - 06-21-2018, 03:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB