3

i've passed some parameters from a view to a controller function. i see them in the url like : .../view/a1312014031 but i'm not able to use them in the function

here is the view

<a href="<?php echo base_url() ?>visiteur/view/<?php echo $id; echo $mois; ?>" class='btn btn-primary'>Mettre en paiement </a>

here is the controller function

public function view($id = '', $mois = '') {
    ......
    $page = 'visiteur_liste';
    $this->load->view('visiteur/' . $page, $data);
    ....
    }

after clicking the link i get url with the parameters.../view/a1312014031 is there a solution to use those parameters in the function without using the session? thanks for your time

5
  • where are you using session here? Commented Mar 19, 2014 at 11:36
  • And also, you'l need to separate both parameter in url by "/", like, <?php echo $id."/"; echo $mois; ?> Commented Mar 19, 2014 at 11:37
  • i'm not using session, i know it's one solution. but i'm wondering if i can do it without... Commented Mar 19, 2014 at 11:39
  • i've tried this but i get Undefined variable: id! is it possible to pass thos parameters to the controller another way than the url Commented Mar 19, 2014 at 12:08
  • OK, Number 1: you pass methods FROM controller TO view... Number 2: if your getting undefined variabel $id.. (assume this is in your VIEW, not your CONTROLLER because you define $id in the controller params...) means you have probably not passed the data to the view properly, it should be passed as key=>value array pair $data = array('id'=>1234); Commented Mar 19, 2014 at 12:13

2 Answers 2

4

Ok, then

You'l need to separate your parameter value in your hyperlink by "/", like:

HTML

<a href="<?php echo base_url() ?>visiteur/view/<?php echo $id.'/'.$mois; ?>" class='btn btn-primary'>Mettre en paiement </a>

PHP

public function view($id = '', $mois = '') { //function in CodeIgniter Controller (visiteur)
    ......
    $page = 'visiteur_liste';
    $this->load->view('visiteur/' . $page, $data);
    ....
}

ANOTHER WAY: PASS DATA USING GET PARAMETERS:

<a href="<?php echo base_url() ?>visiteur/view?id=<?php echo $id.'&mois='.$mois; ?>" class='btn btn-primary'>Mettre en paiement </a>

GET IN CodeIgniter

public function view() {  //function in CodeIgniter Controller (visiteur)
        $id=$this->input->get("id"); // or, $id=$_GET["id"];
        $mois=$this->input->get("mois"); // or, $mois=$_GET["mois"];

}
Sign up to request clarification or add additional context in comments.

4 Comments

@Log1c I want to use second method. its not working for me? shows page not found error. how to resolve it?
I think you didn't rewrote URLs to remove index.php from URL. In my example I didn't mensioned. So your URL should be like this--> http://your.domain.com/index.php/controller_name/function?param=param_value&param2=value2
Can you tell me your URL ?
If you aren't making a slash delimited string, please do not manually build a URL query string. See http_build_query() ...but then you need to worry about non-whitelisted characters too.
0

try this

<a href="<?php echo base_url() ?>visiteur/view/<?php echo $id;?>/<?php echo $mois; ?>" 
   class='btn btn-primary'>Mettre en paiement </a>

2 Comments

Thanks, your solution works partly, i get this url ..view/a131/201403 but when i echo $mois and $id in the controler function, i only get the value of the second parameter ($mois) which is 201403 in the url. if i put $id at the second place like <?php echo $mois ;?>/<?php echo $id; ?>, i only get $id value but not $mois.
try this in controller public function view($id =null,$mois=null)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.