Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Query Strings
#1

[eluser]Craig N[/eluser]
Hi all,

I'm using CI with query strings turned on due to the hosting environment I'm creating this web app for. My question is pretty simple although I can't seem to find it - how do I pass arguments to the methods in my controllers? I'm used to using uri segments like index.php/controller/method/argument 1/argument 2/etc. I did a search and didn't find this in the user guide and trying to pass the arguments as normal get variables didn't seem to work either.

Thanks in advance Smile
#2

[eluser]Colin Williams[/eluser]
Add slashed params

http://www.example.com/controller/functi...param2/etc

I believe you'll only get /id/ passed to your controller, but the rest should be captured with $this->uri->segment(n) or other Uri class functions

EDIT:

Quote:Your function will be passed URI segments 3 and 4 ("sandals" and "123"):

Doesn't get much clearer than that.
#3

[eluser]metaltapimenye[/eluser]
what arguments are u expected come from?.. as exemple, it could come from anything.
Code:
function student_detail($id){
  $s='SELECT * FROM student WHERE behaviour="'.$this->input->post('too_naughty').'" ORDER BY boob '.$this->session->userdata('sort');
  $q=$this->db->query($s);
  $data['result']=$query->result_array();
  $this->load->view('student_detail',$data);
}
#4

[eluser]Craig N[/eluser]
I'm using query strings Colin, not slashed params i.e. index.php?c=controller&m=method. Are you suggesting passing urls like index.php?c=controller&m=method/param1/param2/ ? That doesn't seem right.


for example, let's say I've got a main controller and a search method Normally I would go
index.php/main/search/keywords/

to get my search results. However using query strings I have to go to the URL index.php?m=main&c=search. How do I pass the keywords without using a $_POST variable? If I try &keywords=some+keywords, I can't retrieve it as a $_GET variable.
#5

[eluser]metaltapimenye[/eluser]
hooo.... $this->input->get(), as writen at <a href="http://ellislab.com/codeigniter/user-guide/libraries/input.html">User Guide</a> $this->input->get('something') as replacement for $_GET.

..but i havent tested yet dough. >_<

i wonder how does 'index.php?c=class&f=function&p1=param1' could be able in CI in the first place?

on my perspective it would be nicer if 'index.php/c/class/f/function/p1/param1' to read.. <soon i'll put some .htacces to remove 'index.php' part>
#6

[eluser]metaltapimenye[/eluser]
i found it..

..and tried it.. for sure 'query string' development in CI havent end yet.

Code:
function something(){#i still cannot get the way to put argument in it
  $a=$this->input->get('a');
  $b=$this->input->get('b');
  return $a.$b;}
#7

[eluser]Craig N[/eluser]
Awesome, thanks! Yeah, I like the /controller/method/arg1/arg2/ version too, but unfortunately I can't use it on this project due to the company hosting their domain with their cms provider (which has some messed up htaccess rules)
#8

[eluser]Bramme[/eluser]
example.com/controller/method/var1/var2

translates to
Code:
class Controller {
     function method($var1 = '', $var2 = '') {
     }
}

edit: basically what Michael said in his first reply.
#9

[eluser]Phil Sturgeon[/eluser]
[quote author="Bramme" date="1221573497"]example.com/controller/method/var1/var2

translates to
Code:
class Controller {
     function method($var1 = '', $var2 = '') {
     }
}

edit: basically what Michael said in his first reply.[/quote]

He's looking for normal query strings, not CI url segments. Listen to the mans request ;-)

I'm very glad they added $this->input->get(); it has made everyone's lives a little easier.




Theme © iAndrew 2016 - Forum software by © MyBB