Welcome Guest, Not a member yet? Register   Sign In
how to pass data to view??
#11

[eluser]yudahebat[/eluser]
No. I have it on my DB
#12

[eluser]Thorpe Obazee[/eluser]
[quote author="yudahebat" date="1238750030"]No. I have it on my DB[/quote]

what is on your db?

I suggest you read the user_guide really well.
#13

[eluser]yudahebat[/eluser]
mission six

it still error

Code:
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: views/testpage.php

Line Number: 8

and another 3 error
#14

[eluser]yudahebat[/eluser]
Code:
what is on your db?

this my db
its call mrputucar
and the tabel call testimonial
Code:
id testimonial | tanggal     | email      | nama       | isi|
15            |  2009-24-04 | [email protected] | kerean | yeahhhhh ..... cooll|
and many more...


but its still didnt display on my view

I've load my database also on autoload function
#15

[eluser]Thorpe Obazee[/eluser]
Post what you have now... controller and view.
#16

[eluser]yudahebat[/eluser]
this my controller

Code:
<?php
class Test extends Controller
{
    function Test()
    {
        parent::Controller();
    }
    
    function index($data)
    {
        $data['vars'] = $data;

        $this->load->view('testpage',$data);    
        
    }    
    
    function choose_data($id=0)
    {
        $this->db->where('id_testimonial',$id);
        $query = $this->db->get('testimonial');
        if ($query->num_rows() > 0)
        {
            $data = $query->row();
        }
        $this->index($data);
    }
}

this my view

Code:
<html>
<head>
<title>testpage</title>
</head>

<body>
<?php
echo $vars->tanggal;
echo '<br />';
echo $vars->email;
echo '<br />';
echo $vars->nama;
echo '<br />';
echo $vars->isi;
?&gt;
&lt;/body&gt;
&lt;/html&gt;

when I write
Code:
http://localhost/ci2/test/choose_data/15
on my url
its produce
Code:
Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\CI2\system\application\controllers\test.php on line 11

any idea??
#17

[eluser]Thorpe Obazee[/eluser]
Code:
&lt;?php
class Test extends Controller
{
    function Test()
    {
        parent::Controller();
    }
    
    function index($data)
    {
        $viewdata['vars'] = $data;

        $this->load->view('testpage',$viewdata);    
        
    }    
    
    function choose_data($id=0)
    {
        $this->db->where('id_testimonial',$id);
        $query = $this->db->get('testimonial');
        if ($query->num_rows() > 0)
        {
            $data = $query->row();
        }
        $this->index($data);
    }
}

this should do it.
#18

[eluser]missionsix[/eluser]
Hmm, sorry my example didn't work, I didn't test it...

why not just use
Code:
$this->load->view('testpage',$viewdata);

in the choose_data function?

I don't see why you need to route your data from /Test/choose_data through index? If the views are the same, you could write a simple display function eg:

Code:
class Test extends Controller
{
    function Test()
    {
        parent::Controller();
    }
    
    [...]

    function _display($data) {
        $this->load->view('testpage',$viewdata);
    }



And then call $this->_display($data) instead of $this->index() to display your page?

The error is really telling you what you need to know. Look at the line number in your code, and interpret the error accordingly...
#19

[eluser]yudahebat[/eluser]
it works.... if I call
Code:
http://localhost/ci2/test/choose_data/4
thnx...

but if I call
Code:
http://localhost/ci2/test
it error
how can I display index.php
if I didnt choose database from choose_data function??
#20

[eluser]Thorpe Obazee[/eluser]
of course it would cause an error.




Theme © iAndrew 2016 - Forum software by © MyBB