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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:04:43+00:00 2026-05-24T16:04:43+00:00

Example #1 bschaeffer’s answer to this question – in his last example: $this->load->model(‘table’); $data

  • 0

Example #1

bschaeffer'sanswer to this question – in his last example:

$this->load->model('table');
$data = $this->table->some_func();
$this->load->view('view', $data);

How do you handle this when 'table' doesn’t exist?


Example #2

    try {
        $this->load->model('serve_' . $model_name, 'my_model');
        $this->my_model->my_fcn($prams);

        // Model Exists

    } catch (Exception $e) {
        // Model does NOT Exist
    }

But still after running this (obvously the model doesn’t exist – but sometimes will) it fails with the following error:

An Error Was Encountered

Unable to locate the model you have specified: serve_forms


I am getting this function call by:

1) Getting some JSON:

"model_1:{"function_name:{"pram_1":"1", "pram_2":"1"}}

2) And turning it into the function call:

$this->load->model(‘serve_’ . “model_1”, ‘my_model’);

3) Where I call:

$this->my_model->function_name(pram_1=1, pram_2=1);

SOLUTION

The problem lies in the fact that CodeIgniter’s show_error(...) function displays the error then exit; … Not cool … So I overrode: model(...) -> my_model(..) (you’ll get errors if you just override it) and removed the show_error(...) because for some reason you can’t override it – weird for Codeigniter). Then in my_model(...) made it throw an Exception

My personal opinion: the calling function should return
show_error("message");
where show_error returns FALSE — that or
you could take out the exit; – and make show_error(...)
overridable

  • 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-05-24T16:04:45+00:00Added an answer on May 24, 2026 at 4:04 pm

    You can see if the file exists in the models folder.

    $model = 'my_model';
    if(file_exists(APPPATH."models/$model.php")){
       $this->load->model($model);
       $this->my_model->my_fcn($prams);
    }
    else{
      // model doesn't exist
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: // access fields directly private void doThis() { return doSomeWork(this.data); } // receive
Example: The user login to the webpage => Click on a button This action
Example current URL http://www.domain.com/subdomain/install/finish.php I use this code to get the current URL. $url
Example code: http://jsbin.com/eqile3/ This is a slider with 2 handles, 1 for min and
Example client put this on their website <script type=text/javascript src=http://domain.com/banner.php?bid=123&affid=88></script> In my banner.php how
example <reference>employee</reference> <data>123</data> how to parse using c# so that i should get employee
Example page: http://vincent-massaro.com/columns/columns.html On this page, there are two ordered lists, one with four
Example page I'm working on I used technique mentioned on this page : Basically
Example: $this->getResponse() ->appendBody('Hello' . $name) In the previous example, I understand the use of
Example 1 /** *Program Name: Cis36L0411.java *Discussion: Class -- Data Members ONLY * Method

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.