My Request helper or library - 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: My Request helper or library (/showthread.php?tid=33690) |
My Request helper or library - El Forum - 09-05-2010 [eluser]Ngulo[/eluser] hi all i'm trying to build up my simple personal request_helper just to verify if requests isPost() or isGet() or isAjax() i named my helper as request_helper and i load it by default in the autoload class. i'm trying coding it so: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); when i make Code: if($this->request->isPost()) the result is Code: Call to a member function isPost() on a non-object have you any suggestion guys ? My Request helper or library - El Forum - 09-05-2010 [eluser]slowgary[/eluser] Did you load the helper? Code: $this->load->helper('request'); Also, I believe your methods are incorrect (I could be wrong). You should be able to use this: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); My Request helper or library - El Forum - 09-05-2010 [eluser]Ngulo[/eluser] hi slowgary .... the helper is loaded by default from the system....a put them into autoload.php array helpers i can't really don't why i can't use these methods have you any other suggestion? My Request helper or library - El Forum - 09-05-2010 [eluser]slowgary[/eluser] I recommend reading through the user guide when you have a specific problem like this. Here's the reference for helpers: http://ellislab.com/codeigniter/user-guide/general/helpers.html When you load a helper, you're just including a file. There's no magic that will take your functions and make them methods of an object. This mean that when you use your helper functions, you'll just call them like normal function, not methods of an object: Code: $this->load->helper('request'); Code: $this->request->isPost(); I hope this helps. My Request helper or library - El Forum - 09-05-2010 [eluser]Ngulo[/eluser] oh my god ....you're right man .... and if would like to use $this->request->isPost(); need i to transform my helper into a library? really thanks man My Request helper or library - El Forum - 09-05-2010 [eluser]slowgary[/eluser] Exactly. Libraries are for classes, helpers and plugins are just procedural functions. Create a class with your functions, stick it in the application/libraries directory and load it with $this->load->library('request'), then you can call $this->request->isPost(). Just a recommendation, CodeIgniter uses_underscores as opposed to CamelCase. For consistency, you might want to consider naming your functions is_post(), is_get() and is_ajax(). My Request helper or library - El Forum - 09-05-2010 [eluser]Ngulo[/eluser] thank you slowgary Code: <?php Code: $this->load->library('request'); did you find some other errors please ? really really thanks My Request helper or library - El Forum - 09-05-2010 [eluser]slowgary[/eluser] This is covered in the user guide: http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html Code: class CI_Request extends Controller That's how you write a controller, not a library. Check out the user guide for more info. Good luck. My Request helper or library - El Forum - 09-06-2010 [eluser]InsiteFX[/eluser] Also CI_ is a CodeIgniter resevered word and should not be used in your Controllers Libraries etc. InsiteFX |