Welcome Guest, Not a member yet? Register   Sign In
Model does weird(solved)
#1

[eluser]Jesse2303[/eluser]
PROBLEM SOLVED

Hi all

I've forgooten to make my models and now when I'm trying to make them I get stuck every time.

I want to show the last 3 titels of the news, links, pictures.

Can you look @ my script please ?

Class: Main, Function dashboard()
Code:
function dashboard() {
        
        
        $this->load->model('show');
        
        $data['query']        =     $this->show->get_nieuws();
        $data['link']         =     $this->show->get_links();
        $data['pics']         =     $this->show->get_pics();

        $this->load->view('dashboard_view', $data);

        }
Class Show, Function get_nieuws, get_links, get_pics
Code:
class Show extends Model {
    
    function Show() {
        
        parent::Model();
        
    }
    
    function get_nieuws() {
        
        $get_nieuws = $this->db->query('SELECT * FROM nieuws ORDER BY datum DESC LIMIT 3');
        
    }
    
    function get_links() {
        
        $get_links = $this->db->query('SELECT * FROM links ORDER BY id DESC LIMIT 3');
    
    }
    
    function get_pics() {
        
        $get_pics = $this->db->query('SELECT * FROM pics ORDER BY datum DESC LIMIT 3');
        
    }
}

My output script
Code:
<?php foreach($query->result() as $row):?>
                
[&lt;?=date('H:i', $row->datum);?&gt;] &lt;?=anchor('main/nieuws_bekijk/'.$row->nieuwsid, $row->onderwerp);?&gt;<br />
                
&lt;?php endforeach; ?&gt;

Fatal Error: Call to a member function_result() on a non-object in ... on line 31

Line 31 in that file:
Code:
&lt;?php foreach($query->result() as $row):?&gt;
#2

[eluser]Armchair Samurai[/eluser]
Well, you're not actually returning anything from your model functions - you might want to start there. What is the error you're getting? It wasn't clear from your initial post.
#3

[eluser]Yash[/eluser]
You can't directly use model like this.or I've not tried Sad

anyways

MY_Model.php
Code:
&lt;?php
class BaseModel extends Model {
    function __construct(){
        parent::__construct();
    }

        //Your code here
}
?&gt;

class Post extends BaseModel {
   //Your code here
}

or
Code:
class Post extends Model {
  ststic function doit(){
    return '123';
  }
  
  function get_123(){
    return self::doit();
  }
}
thanx to Sam Dark for code
#4

[eluser]Jesse2303[/eluser]
[quote author="Yash" date="1214397605"]You can't directly use model like this.or I've not tried Sad

anyways

MY_Model.php
Code:
&lt;?php
class BaseModel extends Model {
    function __construct(){
        parent::__construct();
    }

        //Your code here
}
?&gt;

class Post extends BaseModel {
   //Your code here
}

or
Code:
class Post extends Model {
  ststic function doit(){
    return '123';
  }
  
  function get_123(){
    return self::doit();
  }
}
thanx to Sam Dark for code[/quote]

I dont get that :-S


[quote author="Armchair Samurai" date="1214397360"]Well, you're not actually returning anything from your model functions - you might want to start there. What is the error you're getting? It wasn't clear from your initial post.[/quote]

Fatal Error: Call to a member function_result() on a non-object in ... on line 31

Line 31 in that file:
Code:
&lt;?php foreach($query->result() as $row):?&gt;

I've tried this to but it doesn't work:
Code:
function get_nieuws() {
        
        $get_nieuws     =     $this->db->query('SELECT * FROM nieuws ORDER BY datum DESC LIMIT 3');
        Return $get_nieuws->result();
        
    }




Theme © iAndrew 2016 - Forum software by © MyBB