Welcome Guest, Not a member yet? Register   Sign In
What is that I am doing wrong?
#1

[eluser]xoail[/eluser]
I am getting this error:
Fatal error: Call to a member function result() on a non-object in C:\wamp\www\example\system\application\views\user_view.php on line 5

my user_view file is:
Code:
<h1>Title</h1>
&lt;?php foreach ($query->result() as $row)
{
   echo $row['new_text'];
   echo $row['username'];
   echo $row['date'];
}?&gt;

and User controller:
Code:
class User extends Controller {

    function User()
    {
        parent::Controller();
    }
    function index()
    {
    
        $this->load->model('user_model');

        
        $loggedin['status'] = $this->redux_auth->logged_in();
        if ($loggedin == true)
        {
        $data['query'] = $this->user_model->UserText();
        $data['content'] = $this->load->view('user_view', $data, true);
        }
        $this->load->view('template', $data);
        }
}

and user_mode:
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class user_model extends Model {

    function user_model()
    {
         parent::Model();
    }
   function UserText()
    {
        $identity = $this->redux_auth->GetIdentity();
        $useremail = $this->session->userdata('email');
        $this->db->select('p.new_text, u.username, p.promisedate FROM news p join users u on p.newusr= u.id where p.newusr = (select id from users where email = "'.$this->session->userdata('email').'")', FALSE);
        $query = $this->db->get();
        return $query->result();
    }

Thanks!
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

You're getting the query_result() and not the query_array().

query_array() returns an array

query_result (aka result()), returns an object.

You either need to use the result like an object (echo $row->new_text), instead of an array, or get the result array.

Hope that makes sense.
#3

[eluser]xoail[/eluser]
thanks for a quick reply.. heres how the code looks now... but I wont see any data..

user_view;
Code:
<h1>Title</h1>
&lt;?php foreach ($query->result_array() as $row)
{
   echo $row['new_text'];
   echo $row['username'];
   echo $row['date'];
}?&gt;

user controller:
Code:
&lt;?php
class User extends Controller {
    function User()
    {
        parent::Controller();
    }
    function index()
    {
        $this->load->model('user_model');
        $loggedin['status'] = $this->redux_auth->logged_in();
        if ($loggedin == true)
        {
        $data['query'] = $this->user_model->UserText();
        $data['content'] = $this->load->view('user_view', $data, true);
        }
        $this->load->view('template', $data);
    }

user model:
Code:
function UserText()
    {
        $identity = $this->redux_auth->GetIdentity();
        $useremail = $this->session->userdata('email');
        $this->db->select('p.new_text, u.username, p.date FROM news p join users u on p.newusr = u.id where p.newusr = (select id from users where email = "'.$this->session->userdata('email').'")', FALSE);
        $query['news'] = $this->db->get();
        return $query['news'];//$query->result_array();
    }
#4

[eluser]pistolPete[/eluser]
I guess the function user_model->UserText(); is not called because of your login check:
Code:
$loggedin['status'] = $this->redux_auth->logged_in();
if ($loggedin == true)

It probably should be changed to something like this:
Code:
$loggedin = $this->redux_auth->logged_in();
#5

[eluser]TheFuzzy0ne[/eluser]
Well spotted, Pete!

I second Pete's suggestion, you're checking if loggedin is TRUE (type bool), but it's of type "array".
#6

[eluser]xoail[/eluser]
yup.. that was it.. thanks a lot guys..




Theme © iAndrew 2016 - Forum software by © MyBB