Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9024077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:55:05+00:00 2026-06-16T05:55:05+00:00

I new to CI and doubt about to CI controller, I have a pages

  • 0

I new to CI and doubt about to CI controller, I have a pages controller which is an index and use to load header, footer and all pages in a view, as below:

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);

}
}

then I built a registration form which is use captcha library in the form, I found a sample of captcha controller as below:

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);

    }
}
}

here is my view named 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>

my problem is, how could I make Captcha controller load into Pages controller in order to process the function when I call url http://site.com/ci/register page? currently the page will show error as below:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: image
Filename: pages/register.php
Line Number: 65

Please advise, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:55:06+00:00Added an answer on June 16, 2026 at 5:55 am

    when you call to pages controller , the capcha controller is not invoking , instead of using it as a controller make it a library ,

    load it in the ‘pages’ controller .

    $this->load->library('Captcha');
    

    then call to captcha library from your pages controller

    $data['image'] = $this->captcha->index();
    

    now the captcha library looks like this.

    class Captcha  {
    
    
    public function __construct()
        {
            $this->ci =& get_instance();
        }
    
    public function index()
    {
    
        $this->ci->load->library('session');
        $this->ci->load->helper(array('captcha','url'));
    
    
        if ($this->ci->input->post() && ($this->ci->input->post('secutity_code') == $this->ci->session->userdata('mycaptcha'))) {
            $this->ci->load->view('process.php');
        }
        else
        {
    
            $this->ci->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 = $this->create_captcha($vals);
    
            $this->ci->session->set_userdata('mycaptcha', $cap['word']);
    
            return $cap['image'];
        }
    }
    }
    

    hope this helps .

    UPDATE

    my mistake

    use

    $cap = create_captcha($vals);
    

    instead of

    $cap = $this->create_captcha($vals);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a doubt about orkut's new URL Writing method. Earlier the home page
I have a little doubt about javascript, a new language that I'm studying... I
I have a doubt about threading basics. If I launch a new thread T1
I am new to specflow and a have a doubt about how to mock
I'm getting my hands on JSF 2.0 and have certain doubt about new annotation
I am new to Java NIO.I have a small doubt. If I use the
Am new in android. I have some doubt about the general features of android
I am new to this forum. I have a doubt about JSP/servlet in my
Hello i am new in iphone development, I have some doubt about this ,
i have one doubt,i have created new project in eclipse with android 2.3.1 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.