Welcome Guest, Not a member yet? Register   Sign In
[Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice
#3

[eluser]wild thing[/eluser]
Hi,

I had actually posted the entire source code with a link, but apologies, I guess it wasn't clear. I am now attaching the source with the post:

Code:
/*
General configuration:
config.php - $autoload['libraries'] = array('database', 'session');
routes.php - $route['default_controller'] = "blahg";
constants.php - define('WEBSITE_TITLE',                            'Blahg v0.1a');
database.php - db settings (username, db, password)
*/

//Controller Code - /application/controllers/blahg.php

<?php

class Blahg extends Controller {
    
    function Blahg() {
        parent::Controller();
    }
    
    function index() {
        
        //$data['page_title'] = WEBSITE_TITLE.' | Blahg List';
        
        $this->load->model('Posts_model', 'posts');
        
        if($posts)
            echo "Success";
        else
            echo "Failure";
        
        //$data['posts'] = $Posts_model->get_posts(10);
        
        //$this->load->view('blahg_view', $data);
    }
    
}

?>

//Model Code - /application/models/posts_model.php
<?php

class Posts_model extends Model {

    private $title = '';
    private $content = '';
    private $added = '';
    private $updated = '';
    
    function Posts_model() {
        parent::Model();
    }
    
    function get_posts($number_of_posts) {
        $query = $this->db->get('posts', $number_of_posts);
        return $query->result();
    }
    
}
?>

//View Code - /application/views/blahg_view.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;link href="css/core.css" rel="stylesheet" type="text/css" /&gt;
&lt;link href="css/posts.css" rel="stylesheet" type="text/css" /&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?php echo $page_title; ?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;!-- Blog Entries List  --&gt;
&lt;?php
//Load Blahg entries
    
    foreach($posts as $post)
    {
    ?&gt;
    
    <div>
        <h3>&lt;?php echo $post['title'] ?&gt;</h3>
        <div class="date">
        added &lt;?php echo $post['added']; ?&gt;
        &lt;?php
            if($post['updated'])
            {
        ?&gt;
         | updated &lt;?php echo $post['updated']; ?&gt;
        &lt;?php
            }
        ?&gt;
        </div>
    </div>
    
    &lt;?php
    }
    ?&gt;
&lt;/body&gt;
&lt;/html&gt;


Messages In This Thread
[Solved] Cannot get model in 'Hello World' project to work - getting undefined variable notice - by El Forum - 07-06-2008, 06:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB