My Request helper or library |
[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 ?
[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');
[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?
[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-gui...lpers.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.
[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
[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().
[eluser]Ngulo[/eluser]
thank you slowgary Code: <?php Code: $this->load->library('request'); did you find some other errors please ? really really thanks
[eluser]slowgary[/eluser]
This is covered in the user guide: http://ellislab.com/codeigniter/user-gui...aries.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.
[eluser]InsiteFX[/eluser]
Also CI_ is a CodeIgniter resevered word and should not be used in your Controllers Libraries etc. InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |