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

  • Home
  • SEARCH
  • 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 8302219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:13:56+00:00 2026-06-08T17:13:56+00:00

CodeIgniter 2.1.2 I have a class that contains two methods, for the purpose of

  • 0
  • CodeIgniter 2.1.2

I have a class that contains two methods, for the purpose of this questions showone and view. The latter returns all items of a small database and can also perform a search. The other one is for permalinks like domain.com/showone/firstname-lastname

<?php
class Pages extends CI_Controller {

public function view($page)
    {
    //this includes a mysql search
    }

public function showone($slug)
    {
    //abbreviated version:
    $query = "SELECT * FROM mytable WHERE slug = '" . $slug . "'";
    $result = $this->db->query($query);
    if ($result->num_rows() == 0)
        {
        //here is where I'd like to use the same search that I used in showall
        }
    else
        {
        //show the one item
        }
    }

} //class
?>

So if a user decides to directly enter a URL that doesn’t return anything from the database, I would like to direct him to search results instead of showing a 404.

So how do I set up a function searchdatabase($query) to be used by both showone and view?

  • 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-08T17:13:58+00:00Added an answer on June 8, 2026 at 5:13 pm

    You can use your controller functions inside your controller:

    public function view($page)
        {
           $this->showone($slug);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this controller in Code Igniter that begins with class MyController extends CI_Controller
I have this form that validates the fields on submit through ajax (using Codeigniter's
I have a controller something like this in codeigniter: class ABC extends MX_Controller {
I have a view that generates a dynamic navigation bar. Within Codeigniter, I just
i am using codeigniter. i have class Orders which with some methods like start_order(),
I have a Controller called Register that looks like this: class Register extends CI_Controller
Basically, I have a CodeIgniter site that registers users through this url: http://website.com/user/register/1 Unfortunately,
I have a codeigniter code that is working on local Apache installation. But it
I have html elements with class ajaxem that are ment to be used in
I followed this tutorial: http://codeigniter.com/wiki/Internationalization_and_the_Template_Parser_Class/ The controller that loads the language is this one:

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.