CodeIgniter Forums
Get Vars directly to the view (Cleaning Controller) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Get Vars directly to the view (Cleaning Controller) (/showthread.php?tid=12376)



Get Vars directly to the view (Cleaning Controller) - El Forum - 10-16-2008

[eluser]Dewos[/eluser]
Hi all.
For clean my Controller, i want to pass all $_GET vars from URI controller to view directly.

From:

Code:
function index($vars, $id, $name, $abracadaba)
    {        
        $data['vars'] = $vars;
        $data['id'] = $id;
        $data['name'] = $name;
        $data['abracadaba'] = $abracadaba;
        $this->load->view('news/news_view', $data);
    }

To something like this:

Code:
function index($vars, $id, $name, $abracadaba)
    {        
        $this->load->vars($_GET); //for example
        $this->load->view('news/news_view', $data);
    }

In View

Code:
<html>
   <?=$vars?>  
   <?=$id?>  
   <?=$name?>
   <?=$abracadaba?>  
</html>

Any ideas? Smile

Ps. No, $this->input->get() is the same, i think. $this->uri->uri_string() maybe. But it loose the vars name, so it's a wrong way....


Get Vars directly to the view (Cleaning Controller) - El Forum - 10-16-2008

[eluser]Dewos[/eluser]
Ops... wrong section. Sorry :|


Get Vars directly to the view (Cleaning Controller) - El Forum - 10-17-2008

[eluser]xwero[/eluser]
You have to enable query string in the config and set the uri protocol to PATH_INFO. But the query string pairs will not be attached to the controller method. That is only for url segments.


Get Vars directly to the view (Cleaning Controller) - El Forum - 10-17-2008

[eluser]Dewos[/eluser]
[quote author="xwero" date="1224244543"]You have to enable query string in the config and set the uri protocol to PATH_INFO. But the query string pairs will not be attached to the controller method. That is only for url segments.[/quote]

I know... But if vars are aviable in controller, why force to rebind all of them to use in view??. It should be set native by codeigniter controller... will be a real time-saving.

Update:
-func_get_args() useless :|


Get Vars directly to the view (Cleaning Controller) - El Forum - 10-17-2008

[eluser]xwero[/eluser]
There is nothing that stops you from doing this
Code:
<html>
   <?=$_GET['vars']?>  
   <?=$_GET['id']?>  
   <?=$_GET['name']?>
   <?=$_GET['abracadaba']?>  
</html>
but i think you prefer the shorter variable name.

But i think you want to go back to the times where all REQUEST keys where reachable via a variable. This way of programming is insecure and error prone.


Get Vars directly to the view (Cleaning Controller) - El Forum - 10-17-2008

[eluser]Dewos[/eluser]
[quote author="xwero" date="1224255167"]
There is nothing that stops you from doing this
But i think you want to go back to the times where all REQUEST keys where reachable via a variable. This way of programming is insecure and error prone.[/quote]

Ehmm... not and not Smile Only write less.
So, no realistic way... so this is the end, my only friend, the end.