params in controller functions - 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: params in controller functions (/showthread.php?tid=51542) Pages:
1
2
|
params in controller functions - El Forum - 05-08-2012 [eluser]rotivo[/eluser] Hello, i am trying to pass like a second param in a controller function an string, but it seems that only recognize numbers like parameter. I want to pass a query result like a parameter. Copy and paste a peace of the code: Code: if ($this->labola->getData($campo,$patron,$tabla)!==false) I hope your help. Thanks. params in controller functions - El Forum - 05-08-2012 [eluser]ojcarga[/eluser] What does the $query var has in it? If $this->labola->getData($campo,$patron,$tabla) returns a single value I dont see why you can't, but if that is and array maybe you can use serialize() and unserialize() params in controller functions - El Forum - 05-08-2012 [eluser]rotivo[/eluser] Thanks for response...the query returns some rows of three fields from a database.. params in controller functions - El Forum - 05-08-2012 [eluser]ojcarga[/eluser] So, try that way Code: redirect("secciones/pedidos/a/".serialize($query)); And then, in the secciones/pedidos method just get the param and unserialize() it. Just keep in mind that you should not pass sensitive information trough that way. params in controller functions - El Forum - 05-08-2012 [eluser]rotivo[/eluser] It´s not sensitive info...but, ¿How can i pass query results to controller, not being this form???? Thanks. params in controller functions - El Forum - 05-08-2012 [eluser]ojcarga[/eluser] I would do it using Flashdata: Code: $this->session->set_flashdata('the_name_you_want', $query); And then, in the secciones/pedidos method you just get it using Code: $this->session->flashdata('the_name_you_want'); params in controller functions - El Forum - 05-08-2012 [eluser]rotivo[/eluser] Thanks for the help... I´ve tried with sessions and now i could get to pass the query to the controller, but it fails to show it in a loop in the view. The error is: Fatal error: main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CI_DB_mysql_result" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in D:\ I would appreciate your help, thanks. params in controller functions - El Forum - 05-08-2012 [eluser]ojcarga[/eluser] Two things: 1) Please post the code you are using inside this method: Code: getData($campo,$patron,$tabla); 2) Post code of your View where you are trying to show it. "...but it fails to show it in a loop in the view..." params in controller functions - El Forum - 05-08-2012 [eluser]rotivo[/eluser] OK: FUNCTION: Code: public function getData($campo, $patron, $tabla) CONTROLLER: get from session flashdat and send to the view: Code: $data['buscar']=$this->session->flashdata('order'); VIEW: Code: <?php foreach ($buscar->result() as $row) { ?> params in controller functions - El Forum - 05-08-2012 [eluser]ojcarga[/eluser] Ok, right now I'm not in my pc so can't test this but I guess you are getting that error cause the <b>getData($campo, $patron, $tabla)</b> method is returning <b>return $query;</b> ,,, I would try using return <b>$query->result();</b> OR also <b>$query->result_array();</b> And in the view change it for <b>foreach ($buscar as $row)</b> http://ellislab.com/codeigniter/user-guide/database/results.html Let me know what happened :-) |