【发布时间】:2019-07-15 11:44:03
【问题描述】:
我是 Codeigniter 的新手。我尝试将一些数据传递到视图中。我有这样的路线:
$route['accounts/(:any)'] = 'accounts/$1';
在我的 Account 类中,我有这样的注册功能:
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');
}
然后在我的 register.php 中,我尝试像这样打印 $crsf:
<input type="hidden" name="<?=$csrf['name'];?>" value="<?=$csrf['hash'];?>" />
当我访问我在 compro.xyz/accounts/register 中的页面时,它给了我这个错误:
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
" />
好像我的注册机无法识别$csrf。我真的不知道是什么原因造成的,我通常使用 Twig,因为它是 Codeiginter,所以我对它了解不多。目前我正在使用最新版本。
【问题讨论】:
标签: php codeigniter codeigniter-3