How can I use custom class? |
[eluser]greedyman[/eluser]
I have a class as below, I putted it in helpers folder and autoload it: Code: <?php And use it inside a view file: Code: $obj = $this->text->get_instance(); Quote:A PHP Error was encountered
[eluser]Otemu[/eluser]
Hi, Quote:Helpers are not written in an Object Oriented format. They are simple, procedural functions. Here an example taken from StackOverflow that should help you: Create a file and put the following code into it. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Save this to application/helpers/ . We shall call it "new_helper.php" The first line exists to make sure the file cannot be included and ran from outside the CodeIgniter scope. Everything after this is self explanatory. Using the Helper This can be in your controller, model or view (not preferable) Code: $this->load->helper('new_helper'); If you use this helper in a lot of locations you can have it load automatically by adding it to the autoload configuration file. Code: $autoload['helper'] = array('new_helper');
[eluser]greedyman[/eluser]
[quote author="Otemu" date="1361804003"]Hi, Quote:Helpers are not written in an Object Oriented format. They are simple, procedural functions. Here an example taken from StackOverflow that should help you: Create a file and put the following code into it. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Save this to application/helpers/ . We shall call it "new_helper.php" The first line exists to make sure the file cannot be included and ran from outside the CodeIgniter scope. Everything after this is self explanatory. Using the Helper This can be in your controller, model or view (not preferable) Code: $this->load->helper('new_helper'); If you use this helper in a lot of locations you can have it load automatically by adding it to the autoload configuration file. Code: $autoload['helper'] = array('new_helper'); [/quote] Thanks in advanced! I'll try to search more instead of give questions.
[eluser]CroNiX[/eluser]
You can also use your own classes. See the userguide for Creating your own Libraries.
[eluser]greedyman[/eluser]
[quote author="CroNiX" date="1361837770"]You can also use your own classes. See the userguide for Creating your own Libraries.[/quote] Thanks! I done. |
Welcome Guest, Not a member yet? Register Sign In |