Welcome Guest, Not a member yet? Register   Sign In
what wrong with this function
#1

[eluser]yudahebat[/eluser]
what wrong with this controller??

I have a controller like this

Code:
<?php
class Test extends Controller
{
    function Test()
    {
        parent::Controller();
    }
    
    function index()
    {
            
    $data['tanggal']    = '';
        $data['email']         = '';
        $data['nama']         = '';
        $data['isi']         = '';
      
    
    $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);
        }
    
}

and my view like this

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

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

[eluser]Thorpe Obazee[/eluser]
What's the problem you having? Although I doubt your second method would work since CI does an extract on the $data variable when passed to the 'view'.

Code:
$data['yourviewvariable'] = $query->row();
#3

[eluser]yudahebat[/eluser]
upss I forgot to explain my problem,Sorry...
hehehe..

My problem is my controller didn't pass the $data
into the views...

if I write http://localhost/ci2/test/choose_data/15 on url
its display nothing

whats wrong??
#4

[eluser]kgill[/eluser]
For future reference if you want help, explain what the problem is, posting a bunch of code and asking what's wrong with this is far less likely to get you help than you actually telling us what it's supposed to do and what it's doing instead.

Offhand I'd say you're getting a blank page when you expect to see some data and that's because your index function sets a bunch of variables to '' and then echos them out so it's only going to show a blank page. If you call your choose_data function it selects a bunch of data and then tries to pass that to the index function. The problem is your index function doesn't take any parameters, so passing it one doesn't do anything and even if it did because the first thing that function does is set everything to '' whatever you passed in would be wiped out and you'd still end up with a blank page.
#5

[eluser]Thorpe Obazee[/eluser]
[quote author="yudahebat" date="1238745254"]upss I forgot to explain my problem,Sorry...
hehehe..

My problem is my controller didn't pass the $data
into the views...

if I write http://localhost/ci2/test/choose_data/15 on url
its display nothing

whats wrong??[/quote]

Your index doesn't receive parameters from your choose data method.
#6

[eluser]yudahebat[/eluser]
why it doesnt receive??
do you have any idea to fix this??
#7

[eluser]Colin Williams[/eluser]
http://us3.php.net/functions
#8

[eluser]Thorpe Obazee[/eluser]
[quote author="Colin Williams" date="1238749217"]http://us3.php.net/functions[/quote]

Smile
#9

[eluser]TheFuzzy0ne[/eluser]
I always recommend that your index method doesn't accept any arguments.

If you must pass arguments into your index method, you should call it in your URL like this:

http://www.mysite.tld/controller_name/index/arg1/arg2




Theme © iAndrew 2016 - Forum software by © MyBB