Welcome Guest, Not a member yet? Register   Sign In
$this->input->get() - what to link to??
#1

[eluser]umbongo[/eluser]
I am trying to figure out how to use the get in CI.

with regular PHP i would have linked to something like page.php?some_data=value1&some_other_data=valueA

what do i do in CI as there is no *.php in the URL?
#2

[eluser]cahva[/eluser]
If your server is running php as a module in apache, set these in config.php
Code:
$config['uri_protocol']    = "PATH_INFO";

$config['enable_query_strings'] = TRUE;

..thats it! Now you can use for example $this->input->get('some_data') for example:

url: yoursite.com/foo?some_data=value1&some_other_data=valueA
Code:
Class Foo extends Controller {
    
    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        echo $this->input->get('some_data').' '.$this->input->get('some_other_data');
    }

}
#3

[eluser]umbongo[/eluser]
Thanks, awesome!

So i have some variables being set this way, how do i set a default value for them when there is no input from get??

(Also, i don't really understand how you would use your code?? in the example index would print 'value1 valueA'?? Is this just to show that it worked??)
#4

[eluser]Vladimir Aleksiev[/eluser]
[quote author="umbongo" date="1287558723"]Is this just to show that it worked??[/quote]
Yes!
You can set your default values like this:
Code:
Class Foo extends Controller {    
    function __construct(){
        parent::__construct();
    }
    function index(){
        $some_data = (isset($this->input->get('some_data'))?$this->input->get('some_data'):'initial value';
    }
}
This is a shortcut to write if statement.
In my opinion the best way to send parameters to a controller function is to do it codeigniter style, like this.
http://site.com/foo/index/param1/param2
Code:
Class Foo extends Controller {    
    function __construct(){
        parent::__construct();
    }
    function index($param1, $param2){
        echo $param1.' '.$param2;
    }
}
#5

[eluser]cahva[/eluser]
You dont have to use isset() on $this->input->get('something'). It will return FALSE if its not set.
#6

[eluser]Vladimir Aleksiev[/eluser]
My mistake! (:
#7

[eluser]umbongo[/eluser]
OK so i have the following in a function;
Code:
$var = $this->input->get('url_var'):'5';
and this is giving me a parse error in relation to that line??
#8

[eluser]WanWizard[/eluser]
I would give you one too...

What are you trying to do here? What does the :'5' do there?
#9

[eluser]umbongo[/eluser]
well.. i am trying to set the default value where there is nothing to 'get'.. so i was trying to set this to '5' in this example.
#10

[eluser]Vladimir Aleksiev[/eluser]
[quote author="umbongo" date="1287610035"]OK so i have the following in a function;
Code:
$var = $this->input->get('url_var'):'5';
and this is giving me a parse error in relation to that line??[/quote]
This is what you need. (:
Code:
$var = ($this->input->get('url_var'))?$this->input->get('url_var'):'5';




Theme © iAndrew 2016 - Forum software by © MyBB