私はCIを初めて使用し、CIコントローラーについて疑問を持っています。インデックスであり、以下のように、ビュー内のヘッダー、フッター、およびすべてのページをロードするために使用するページコントローラーがあります。
class Pages extends CI_Controller{
function __construct() {
parent::__construct();
$this->load->helper(array('url', 'form', 'captcha'));
$this->load->model('getdb');
$this->load->library('javascript');
$this->load->library('session');
}
public function index($page='home'){
if(!file_exists('application/views/pages/'.$page.'.php')){
show_404();
}
$data['title'] = ucfirst($page);
$data['sitename'] = $this->config->item('site_name');
$data['library_src'] = $this->jquery->script();
$data['script_head'] = $this->jquery->_compile();
$data['results'] = $this->getdb->getAll();
$this->load->view('templates/header', $data);
$this->load->view('inc/mainmenu', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('pages/sidebar', $data);
$this->load->view('templates/footer', $data);
}
}
次に、フォームでキャプチャライブラリを使用する登録フォームを作成しました。以下のようにキャプチャコントローラーのサンプルを見つけました。
class Captcha extends CI_Controller {
public function index()
{
$this->load->library('session');
$this->load->helper(array('captcha','url'));
if ($this->input->post() && ($this->input->post('secutity_code') == $this->session->userdata('mycaptcha'))) {
$this->load->view('process.php');
}
else
{
$this->load->helper('captcha');
$vals = array(
'img_path' => './assets/captcha/',
'img_url' => base_url().'captcha/',
'font_path' => './assets/styles/fonts/MyriadPro-Semibold.ttf',
'img_width' => '200',
'img_height' => '30',
'expiration' => 3600
);
$cap = create_captcha($vals);
$data['image'] = $cap['image'];
$this->session->set_userdata('mycaptcha', $cap['word']);
$this->load->view('pages/register.php', $data);
}
}
}
これがregister.phpという名前の私のビューです:
<div id="content-wrap">
<form method="post" action="<?php echo base_url()?>">
<p><?php echo $image ?></p>
<p>Security: <input type="text" name="secutity_code"></p>
<p><input type="submit" name="submit" value="submit" /></p>
</form>
</div>
http://site.com/ci/register
私の問題は、URLページを呼び出すときに関数を処理するためにCaptchaコントローラーをPagesコントローラーにロードするにはどうすればよいですか?現在、ページには次のようなエラーが表示されます。
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: image
Filename: pages/register.php
Line Number: 65
アドバイス、ありがとう。