Welcome Guest, Not a member yet? Register   Sign In
how to take the url to became a variable
#11

[eluser]sherpa[/eluser]
Code:
function choose_testi($id=0){
    
         /* No need to get segment as thefunction expects the
          * parameter and if not specified the param '0' will be assinged in id default
          */

        //$id = $this->uri->segment(3,0);  // removed
        $this->db->where('id_testimonial',$id);
        $query = $this->db->get('testimonial');
        if($query->num_rows() > 0){ // it should be '$query' not '$user_row' my mistake
            $data[] = $query->row();
        }
        $this->load->view('adm_testimonial',$data);
  
    }
#12

[eluser]yudahebat[/eluser]
no. I need the segment(3) to get the ID of my tabel that I choose
to show on $data

I've tried your code
but I still use
Code:
$id = $this->uri->segment(3);

and I got an error

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: query_row

Filename: controllers/adminpage.php

Line Number: 240

Fatal error: Call to a member function num_rows() on a non-object in C:\xampp\htdocs\CI2\system\application\controllers\adminpage.php on line 240

I also cek your code without editing

and got an error also

no data pass to the view
#13

[eluser]jdfwarrior[/eluser]
Not trying to be mean, but it seems like your having trouble with some really basic stuff with CI/PHP. You really should go back and dig a little more into the user guide. CodeIgniter has awesome documentation. You could probably figure out everything your wanting to know very easily there.
#14

[eluser]yudahebat[/eluser]
I've found how to pass the $data to the view

but on the
Code:
$this->load->view('adm_testimonial',$data);

if I can make it in
Code:
redirect('/admipage/adm_testimonial/');
I think it will be succeed, but I dont know how to pass the $data on redirect function

please help me...
#15

[eluser]jdfwarrior[/eluser]
Well you cant pass data through the redirect function.

If your just trying to access that function and give it the data though, why dont you just call the function rather than doing a redirect. Modify your adm_testimonial function to accept a parameter and do:

Code:
$this->adm_testimonial($data);
#16

[eluser]yudahebat[/eluser]
sorry I dont Understand

my english not so good

where I put that code?? specificlly..
#17

[eluser]jedd[/eluser]
[quote author="yudahebat" date="1238605909"]no. I need the segment(3) to get the ID of my tabel that I choose
to show on $data[/quote]

Okay - the important thing here that I think you are missing is that if you have a function like this:
Code:
function    foo  (  $bar  )  {
          }

Then $bar will be the same as segment(3)

The good thing about using the function ($variable) approach is that you can easily have multiple variables (and they take their value from your URL : http://example.com/Controller/foo/2/3/4/5

You could get each of those values by adjusting the code above to be:
Code:
function   foo  ($bar , $hugo , $bob , $nuggen)  {

In that example, using that URL, you'd find that $bar = 2, $hugo=3, $bob=4, $nuggen=5


The bad thing about using segment(x) is that a) it's harder to read and debug, and b) if you ever adjust your controller file layout - start using sub-directories for example - these numbers are suddenly wrong and you have to re-visit your code.


Now, the reason that you see people write this kind of code:
Code:
function  foo ( $bar = 0 )  {

Is so that IF the URL is just http://example.com/Controller/foo -- so, no trailing number segment -- then $bar will be set to 0, which is more convenient than being 'not set'. If there IS a trailing number on that URL, then it over-rides - and $bar takes on that value.

Does this make more sense?
#18

[eluser]jdfwarrior[/eluser]
modify your adm_testimonials function to accept a parameter (see jedd's post above).

Then replace your redirect function call, with the code I gave you. That will make it run that function (same as going to admpage/adm_testimonials) and you can pass the $data variable to that function. From there you can manipulate it or display whatever you want.
#19

[eluser]yudahebat[/eluser]
I've change my code as your command
do you mean like this??

Code:
function adm_testimonial($id=0)
    {
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css1');
        $data['css1'] = $this->css;
        $data['base'] = $this->base;
        $data['myrobots'] = '<meta name="robots" content="noindex,nofollow">';
        $data['mywebtitle'] = 'mrputucar | data admin testimonial';
        
        $mymenu = $this->menu->menu_adm();
        $data['menu_adm'] = $mymenu;
    
        //This assumes you used the sample MySQL table
        $user_table = 'admin';
        
        //Load the URL helper
        $this->load->view('adm_testimonial',$data);    
        
    }

and choose_testi function

Code:
function choose_testi($id=0){
    
         /* No need to get segment as thefunction expects the
          * parameter and if not specified the param '0' will be assinged in id default
          */

        //$id = $this->uri->segment(3,0);  // removed
        $this->db->where('id_testimonial',$id);
        $query = $this->db->get('testimonial');
        if($query->num_rows() > 0){ // it should be '$query' not '$user_row' my mistake
            $data[] = $query->row();
        }
        $this->adm_testimonial($data);
  
    }

it didn't produce anything on $data

so

Code:
echo $tanggal;
echo $email;
echo $nama;
echo $isi;

undefined...

anything wrong?? please help..
#20

[eluser]yudahebat[/eluser]
I give you the text link on the views
adm_testimonial.php

Code:
echo '<td class="tabel2">';
      echo '<p>';
      echo '<a href="' . site_url('/adminpage/choose_testi/' . $ua['id_testimonial']) . '">Edit</a>';
      echo '</p>';
echo '</td>';




Theme © iAndrew 2016 - Forum software by © MyBB