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

[eluser]Kolin[/eluser]
Thanks for the reply,

i added

Code:
print_r($data);

to the view used for the getArticles function then tried both ways you suggested and the array doesn't contain "section"

Is there anything else i could be doing wrong?

Just out of interest, why is the second way considered better?

--Edit--

Amended code

Code:
<?php

// model
// articles.php
//  

class Articlemodel extends Model {

var $data = array('section' => 'articles');

    //var $data;
    function __construct() {
        parent::__construct();
        //$this->data['section'] = 'articles';
    }
    
    
    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;
    }
    
}

?>

print_r output

Code:
Array ( [view] => articles/category [vars] => Array ( [articles] => Array ( [0] => Array ( [username] => Kolin [id] => 1 [name] => Cat 1 - Test article 1 [description] => Cat 1 - Test article 1 [author_id] => 1 [created] => 2008-09-23 ) [1] => Array ( [username] => Kolin [id] => 2 [name] => Cat 1 - Test article 2 [description] => Cat 1 - Test article 2 [author_id] => 1 [created] => 2008-09-23 ) ) ) [return] => )


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