I'm new at Codeigniter. I try to pass some data into a view. I have a route like this:
$route['accounts/(:any)'] = 'accounts/$1';
and in my Account class i have register function like this:
public function register()
{
$csrf = array(
'name' => $this->security->get_csrf_token_name(),
'hash' => $this->security->get_csrf_hash()
);
$this->load->view('partials/head');
$this->load->view('partials/nav');
$this->load->view('auth/register',$csrf);
$this->load->view('partials/footer');
}
then in my register.php i try to print that $crsf like this:
<input type="hidden" name="<?=$csrf['name'];?>" value="<?=$csrf['hash'];?>" />
when i access my page which in compro.xyz/accounts/register it give me this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: csrf
Filename: auth/register.php
Line Number: 13
Backtrace:
File: D:\xampp\htdocs\compro\application\views\auth\register.php
Line: 13
Function: _error_handler
File: D:\xampp\htdocs\compro\application\controllers\Accounts.php
Line: 19
Function: view
File: D:\xampp\htdocs\compro\index.php
Line: 315
Function: require_once
" value="
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: csrf
Filename: auth/register.php
Line Number: 13
Backtrace:
File: D:\xampp\htdocs\compro\application\views\auth\register.php
Line: 13
Function: _error_handler
File: D:\xampp\htdocs\compro\application\controllers\Accounts.php
Line: 19
Function: view
File: D:\xampp\htdocs\compro\index.php
Line: 315
Function: require_once
" />
seem's like my register doesn't recognize $csrf
. I really have no idea what can cause it, I usually using Twig and since it Codeiginter I don't know much about it. And currently I'm using latest version.