Welcome Guest, Not a member yet? Register   Sign In
Adding to data array for all functions in model
#1

[eluser]Kolin[/eluser]
Hi There,

I'm just in the process of learning OOphp and codeigniter
This is a bit of a nub question im sure but i cant figure it out.

I'm using the array $data[] to send data to my view.

I want to add the section name to $data['section'] for all functions in the model but it wont work.

The error i get it

Quote:Parse error: syntax error, unexpected '[', expecting ',' or ';' in /home/compirc/public_html/development/system/application/models/articlemodel.php on line 9

The code i'm using is

Code:
<?php

// model
// articles.php
//  

class Articlemodel extends Model {

    var $data['section'] = "articles";

    function __construct() {
        parent::__construct();
    }
    
    
    function getCategories(){
        $query = $this->db->query("SELECT * FROM article_categories");
        $categories = $query->result_array();
        $data['categories'] = $categories;
        return $data;
    }
    
    function getArticles(){
        $category = $this->uri->segment(3);
        $query = $this->db->query("SELECT users.username, articles.id, articles.name, articles.description, articles.author_id, articles.created FROM articles LEFT JOIN users ON articles.author_id = users.id WHERE category_id = $category");
        $articles = $query->result_array();
        $data['articles'] = $articles;
        return $data;
    }
    
    function getArticle(){
        $article = $this->uri->segment(3);
        $query = $this->db->query("SELECT * from articles where id = $article");
        $article = $query->row();
        $data['article'] = $article;
        return $data;
    }
    
}

?>

Any help on how to get this to work, or a better way to go about it would be appreciated.

Thanks,
Kolin


Messages In This Thread
Adding to data array for all functions in model - by El Forum - 09-24-2008, 12:43 PM
Adding to data array for all functions in model - by El Forum - 09-24-2008, 12:51 PM
Adding to data array for all functions in model - by El Forum - 09-24-2008, 01:02 PM
Adding to data array for all functions in model - by El Forum - 09-24-2008, 01:29 PM
Adding to data array for all functions in model - by El Forum - 09-24-2008, 01:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB