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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:56:29+00:00 2026-05-19T23:56:29+00:00

Here is some code excerpted from Codeigniter’s user guide about models. There’s no explicit

  • 0

Here is some code excerpted from Codeigniter’s user guide about models. There’s no explicit load of the databass class, in which the object db, method get in the code below have to be defined. I’ve checked the autoload file, there is no autoload of this specific class.

class Blogmodel extends CI_Model {

    var $title   = '';
    var $content = '';
    var $date    = '';

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function get_last_ten_entries()
    {
        $query = $this->db->get('entries', 10);
        return $query->result();
    }

    function insert_entry()
    {
        $this->title   = $_POST['title']; // please read the below note
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->insert('entries', $this);
    }

    function update_entry()
    {
        $this->title   = $_POST['title'];
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->update('entries', $this, array('id' => $_POST['id']));
    }

}
  • 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-19T23:56:30+00:00Added an answer on May 19, 2026 at 11:56 pm

    The CodeIgniter documentation states two methods of loading the database library and connection:

    Database – User Guide

    Automatically Connecting

    The “auto connect” feature will load
    and instantiate the database class
    with every page load. To enable “auto
    connecting”, add the word database to
    the library array, as indicated in the
    following file:

    application/config/autoload.php
    

    Manually Connecting

    If only some of your pages require
    database connectivity you can manually
    connect to your database by adding
    this line of code in any function
    where it is needed, or in your class
    constructor to make the database
    available globally in that class.

    $this->load->database();

    Also, when loading the model as referenced by jss:

    You can tell the model loading
    function to auto-connect by passing
    TRUE (boolean) via the third
    parameter, and connectivity settings,
    as defined in your database config
    file will be used:

    $this->load->model(‘Model_name’, ”,
    TRUE);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a python application from some source code I've found Here I've managed
Here is some code I could not get to format properly in markdown, this
Here's some code I saw once. Can you see what's wrong with it? [updated]
Here's some Ruby code: puts %x{ pstree #{$$} } # never forks puts %x{
const static int foo = 42; I saw this in some code here on
I'm looking for something like break for loops. Here's some example code (using Symfony's
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
I have some code where I'm returning an array of objects. Here's a simplified
First, to make my job explaining a bit easier, here's some of my code:
Given some JS code like that one here: for (var i = 0; i

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.