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 8635493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:59:13+00:00 2026-06-12T09:59:13+00:00

Ok, so i am using codeigniter and tankauth. I want to create a function

  • 0

Ok, so i am using codeigniter and tankauth. I want to create a function where a user can ask a question and the question is stored in the databse. Seems simple enough although I seem to be running into issues once i start creating new classes for the controllers, libraries, and models. Here is what i have done so far:

VIEW: welcome.php (this is the first page, the user can go to the ask_question page with the anchor at the end, well when it works).

<?php echo anchor('/ask/ask_question', 'Ask a Question'); ?></br>

VIEW: ask_question.php

Ask a questsion bro!</br>
</br>
<?php 
$title = array(
           'name' => 'title',
           'id' => 'title',
           'value' => set_value('title'),
           'maxlength' => 750,
           'size' => 30,
           'style' => 'width: 100px',
           );
$body = array(
          'name' => 'body',
          'id' => 'body',
          'value' => set_value('body'),
          'maxlength' => 5000,
          'size' => 30,
          'style' => 'width: 100px',
          );
?>
<?php echo form_open('/Ask/ask_question'); ?>
<table>
    <tr>
        <td><?php echo form_label('Title', $title['id']); ?></td>
        <td><?php echo form_input($title); ?></td>
    <td style="color: red;"><?php echo form_error($title['name']); ?><?php echo isset($errors[$title['name']])?$errors[$title['name']]:''; ?></td>
    </tr>
    <tr>
        <td><?php echo form_label('Body', $body['id']); ?></td>
        <td><?php echo form_input($body); ?></td>
    <td style="color: red;"><?php echo form_error($body['name']); ?><?php echo isset($errors[$body['name']])?$errors[$body['name']]:''; ?></td>
    </tr>
</table>
<?php echo form_submit('ask_question', 'Ask Question'); ?>
<?php echo form_close(); ?>

CONTROLLER: ask.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class ask extends CI_Controller
{
    function __construct()
    {
        parent::__construct();

        $this->load->helper(array('form','url'));
        $this->load->library('Ask_Question');
        $this->load->library('tank_auth');
        $this->load->library('form_validation');
        $this->lang->load('tank_auth');
    }

    function index()
    {
      if (!$this->tank_auth->is_logged_in()) {
        redirect('/auth/login/');
      }
      else {
        $this->load->view('/ask/ask_question/');
      }
    }

    function ask_question()
    {
      if (!$this->tank_auth->is_logged_in()) {
        redirect('/auth/login/');
      }
      elseif ($this->tank_auth->is_logged_in(FALSE)) {
        redirect('/auth/send_again/');
      }
      else {
        $this->form_validation->set_rules('title', 'Title', 'trim|required|xss_clean|min_length[15]');
        $this->form_validation->set_rules('body', 'Body', 'trim|required|xss_clean|min_length[15]');
        if ($this->form_validation->run()) {
          if (!is_null($data = $this->Ask_Question->ask_question(
                                     $this->form_validation->set_value('title'),
                                     $this->form_validation->set_value('body')))) {
        $data['site_name'] = $this->config->item('website_name', 'tank_auth');
          }
          else {
        $errors = $this->Ask_Question->get_error_message();
        foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v);
          }
        }
      }
      $this->load->view('/ask/ask_question/');
    }
}

LIBRARIES: Ask_Question.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once('phpass-0.1/PasswordHash.php');

define('STATUS_ACTIVATED', '1');
define('STATUS_NOT_ACTIVATED', '0');

/**
 * Tank_auth
 *
 * Authentication library for Code Igniter.
 *
 * @package     Tank_auth
 * @author      Ilya Konyukhov (http://konyukhov.com/soft/)
 * @version     1.0.9
 * @based on    DX Auth by Dexcell (http://dexcell.shinsengumiteam.com/dx_auth)
 * @license     MIT License Copyright (c) 2008 Erick Hartanto
 */
class Ask_Question
{
    private $error = array();

    function __construct()
    {
        $this->ci =& get_instance();

        $this->ci->load->config('tank_auth', TRUE);

        $this->ci->load->library('session');
        $this->ci->load->database();
        $this->ci->load->model('questions');

        // Try to autologin
        $this->autologin();
    }

    function ask_question($title, $body)
    {
      $user_id = $this->ci->session->userdata('user_id');
      $class_id = '1';
      $tag1 = 'KENT';
      $this->ci->questions->ask_question($user_id, $class_id, $title, $body, $tag1);
      return NULL;
    }

    function get_error_message()
    {
        return $this->error;
    }
}

MODELS: questions.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Users
 *
 * This model represents user authentication data. It operates the following tables:
 * - user account data,
 * - user profiles
 *
 * @package Tank_auth
 * @author  Ilya Konyukhov (http://konyukhov.com/soft/)
 */
class questions extends CI_Model
{
    private $table_name         = 'users';          // user accounts
    private $profile_table_name = 'user_profiles';  // user profiles

    function __construct()
    {
        parent::__construct();

        $ci =& get_instance();
        $this->table_name           = $ci->config->item('db_table_prefix', 'tank_auth').$this->table_name;
        $this->profile_table_name   = $ci->config->item('db_table_prefix', 'tank_auth').$this->profile_table_name;
    }

    function ask_question($user_id, $class_id, $title, $body, $tag1)
    {
      $this->db->insert('questions', array('user_id'=>$user_id,'class_id'=>$class_id, 'question_title'=>$title, 'question_content'=>$body, 'focus_peak_1'=>$tag1)); 
      return NULL;
    }
}

I have done stuff like this before using the already created class no problem. I have not yet created my own classes. I am not sure if i am doing it write (I just copied the way the current classes are set up). So please let me know if I I have any errors or anything. Right now I cannot get my form to show up at all. the page is just blank.

  • 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-12T09:59:14+00:00Added an answer on June 12, 2026 at 9:59 am

    I’m not sure if this is the only error – but it is one of them – change your ‘capitalisaiton’:

    from ask_question.php:

    <?php echo form_open('/Ask/ask_question'); ?>
    

    to

    <?php echo form_open('/ask/ask_question'); ?>
    

    from ask.php:

     class ask extends CI_Controller
    

    to

     class Ask extends CI_Controller
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Codeigniter, I'm able to create a function for user authentication. I have a
Using CodeIgniter I am trying to create a link that the user can click
I am using codeigniter and what i want to do is when user logs
I am using the codeigniter framework and I am trying to implement the tankauth
I'm using CodeIgniter 2.1 I use CodeIgniter's session to handle whether a user logged
I'm using CodeIgniter + Zend libraries. I want to let users upload videos to
I'm using CodeIgniter for my php framework and TankAuth for my authorization/registration. By default,
I am using Tank Auth for Codeigniter to facilitate user registration and login. Problem:
Using Codeigniter, I have a controller function name search that takes in parameters state
I'm using CodeIgniter's form validation callback function, here is it: function _validate_rate($input, $field) {

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.