-
I wanted to customize registration behavior, so extended RegisterController and tried to use getValidationRules. I wanted to reuse the built-in validation logic and some other pieces. I got "Error: Typed property CodeIgniter\Shield\Controllers\RegisterController::$tables must not be accessed before initialization". Note that I am doing "new MyRegisterController()) and then calling ->method(). Assuming that initController has to be mandatorily overridden, I wrote this: public function initController(
RequestInterface $request,
ResponseInterface $response,
LoggerInterface $logger
): void {
parent::initController(
$request,
$response,
$logger
);
} but that one gave me Fatal error about some compatibility which I did not capture. Can you help? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Can you try the following change? --- a/src/Controllers/RegisterController.php
+++ b/src/Controllers/RegisterController.php
@@ -33,7 +33,7 @@ class RegisterController extends BaseController
/**
* Auth Table names
*/
- private array $tables;
+ protected array $tables;
public function initController(
RequestInterface $request, |
Beta Was this translation helpful? Give feedback.
-
This is the way to customize the controller and I have no problem with it. Or at least I didn't get it right. My Routes.php : service('auth')->routes($routes, ['except' => ['register']]);
$routes->get('register', '\App\Controllers\RegisterController::registerView');
$routes->post('register', '\App\Controllers\RegisterController::registerAction'); my App\Controllers\RegisterController.php: <?php
namespace App\Controllers;
use CodeIgniter\Shield\Controllers\RegisterController as ShieldRegisterController;
class RegisterController extends ShieldRegisterController
{
/**
* Displays the registration form.
*
* @return RedirectResponse|string
*/
public function registerView(){
return 'override';
}
public function myMethod(){
return 'My Method!!';
}
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answers. Here is how I solved it: Next, I added the code below to my registration method at the top. Then I removed all "user" registration based actions/redirections etc. and kept the validations/events/group registration in place. It all worked smoothly. Thanks! |
Beta Was this translation helpful? Give feedback.
Thanks for your answers. Here is how I solved it:
First made the "$tables" protected as @kenjis suggested.
Next, I added the code below to my registration method at the top.
$authConfig = config('Auth'); $this->tables = $authConfig->tables;
Then I removed all "user" registration based actions/redirections etc. and kept the validations/events/group registration in place. It all worked smoothly.
Thanks!