raymond spark
raymond spark

Reputation: 49

cant get passed parameter by url in php

please help me, this is simple thing but I don't know why this still keep error for an hour,

on my view I've got :

<a href="admin/editProduct?idd=$id">

on my controller that directed from above :

public function editProduct(){

        $data["id"] = $_GET['idd'];

        $data["produk"] = $this->model_get->get_data_list(2);
//this below doesn't work either, i just want to past the parameter to my model
        //$data["produk"] = $this->model_get->get_data_list($_GET['idd']);

        $this->adminHeader();
        $this->load->view("adminPages/editProduct", $data);
        $this->adminFooter();
    }

I can not use the array id. It keeps telling me undefined variable idd. I don't know what to do anymore, please anyone help! I am using Codeigniter framework

Upvotes: 0

Views: 415

Answers (4)

athiradivakar
athiradivakar

Reputation: 21

Change your view as:

<a href="admin/editProduct/<?php echo $id;?>">

And in the controller, either get the id as parameter,

  public function editProduct($id) {
  }

or as uri segment

  public function editProduct() {
      $id = $this->uri->segment(3);
  }

Upvotes: 1

Niyaz
Niyaz

Reputation: 2893

make

try this this works fine

  public function editProduct()
     { 
        $id=$this->uri->segment(3); 
        $data["produk"] = $this->model_get->get_data_list($id);
        $this->adminHeader();
        $this->load->view("adminPages/editProduct", $data);
        $this->adminFooter();
    }

Upvotes: 0

Sanjay Kumar N S
Sanjay Kumar N S

Reputation: 4749

Make the href link as follows:

<a href="admin/editProduct/$id">...</a>

And edit the controller like this:

public function editProduct($id){
    ...
    $this->model_get->get_data_list($id); 
}

Where $id will be the passed $id.

Upvotes: 0

Usman Akram
Usman Akram

Reputation: 139

Change your link (in view) with this

<a href="admin/editProduct/$id">

And change your controller as

public function editProduct($id) {

}

Then user $id inside your controller

Upvotes: 0

Related Questions