CodeIgniter Forums
Myth\Auth extending AuthController - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34)
+--- Thread: Myth\Auth extending AuthController (/showthread.php?tid=80768)



Myth\Auth extending AuthController - navblue - 12-15-2021

I'm trying to extend AuthController to make modifications of my own.  I've "published" the controller with the auth:publish spark module, but my application isn't using the new controller in App\controllers\AuthController.php. 

I'm sure I'm missing something stupid.  Any ideas?


RE: Myth\Auth extending AuthController - kenjis - 12-15-2021

Did you set the route for it?


RE: Myth\Auth extending AuthController - navblue - 12-16-2021

I have a route set now! Thanks!

It's been awhile since I've used CodeIgniter and didn't think to configure a route to extend the controller.  Makes sense now in hindsight.  Below is what I have configured in my app\config\routes.php if anyone else makes the same mistake as me in the future (update the namespace). 

Code:
$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
    // Login/out
    $routes->get('login', 'AuthController::login', ['as' => 'login']);
    $routes->post('login', 'AuthController::attemptLogin');
    $routes->get('logout', 'AuthController::logout');

    // Registration
    $routes->get('register', 'AuthController::register', ['as' => 'register']);
    $routes->post('register', 'AuthController::attemptRegister');

    // Activation
    $routes->get('activate-account', 'AuthController::activateAccount', ['as' => 'activate-account']);
    $routes->get('resend-activate-account', 'AuthController::resendActivateAccount', ['as' => 'resend-activate-account']);

    // Forgot/Resets
    $routes->get('forgot', 'AuthController::forgotPassword', ['as' => 'forgot']);
    $routes->post('forgot', 'AuthController::attemptForgot');
    $routes->get('reset-password', 'AuthController::resetPassword', ['as' => 'reset-password']);
    $routes->post('reset-password', 'AuthController::attemptReset');
});