CodeIgniter Forums
access to database from models - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: access to database from models (/showthread.php?tid=34220)



access to database from models - El Forum - 09-23-2010

[eluser]Unknown[/eluser]
Hi, i have a problem.
I write my class in models/content.php
Code:
class Content extends Model
{
    public function __construct()
    {
        parent::Model();
    }
    
    public function display_content($site)
    {    
        $query = $this->database->query('SELECT name, content FROM content WHERE name="{$site}"');
    }
}
and it shows me an error
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Content::$database

Filename: models/content.php

Line Number: 13

What should i do, if i want to use CI database class inside 'models' folder ?


access to database from models - El Forum - 09-23-2010

[eluser]WanWizard[/eluser]
Use
Code:
$this->db->...
?


access to database from models - El Forum - 09-23-2010

[eluser]Unknown[/eluser]
oops :roll: my bad.. sorry, and thanks for quick answer

ps: I promies that i will be more carefully in reading user guide.