extending native libraries |
[eluser]sanjoy[/eluser]
I am facing some problem when trying to extend native library. I have followed all the instruction from http://ellislab.com/codeigniter/user-gui...aries.html , but failure. Please suggest. Thanks in advance for your co-operation.
[eluser]davidbehler[/eluser]
What exactly doesn't work? Describing your problem in more detail might make it easier for others to actually help you.
[eluser]sanjoy[/eluser]
Actually I want to overwrite function output(). I have created a class Hello.php under application/libraries/ as follows <?php if(!defined('BASEPATH')) exit('No direct script access allowed'); class Hello{ function CI_Hello(){ $this->obj=&get;_instance(); } function output(){ return 'Hello World'; } } ?> I have created another file MY_Hello.php under application/libraries/ as follows:- <?php if(!defined('BASEPATH')) exit('No direct script access allowed'); class MY_Hello extends CI_Hello{ function My_Hello(){ parent::CI_Hello(); } function output(){ return 'Overwrite Hello World string generated.'; } } ?> Now I want to overwrite the output() function from controller using [ basically I want output like 'Overwrite Hello World string generated.' ] the following code:- $this->load->library('hello'); $this->hello->output(); Note: I have set $config['subclass_prefix'] on application/config/config.php with $config['subclass_prefix'] = 'MY_'; What's wrong with me. Please suggest.
[eluser]WanWizard[/eluser]
Don't understand what you're trying to do here. There is no CI library called Hello, so trying to extend CI_Hello is not going to work...
[eluser]sanjoy[/eluser]
I want to overwrite the function output().... Following also will not work. <?php //Hello.php if(!defined(‘BASEPATH’)) exit(‘No direct script access allowed’); class Hello{ function Hello(){ $this->obj=&get;_instance(); } function output(){ return ‘Hello World’; } } ?> <?php //MY_Hello.php if(!defined(‘BASEPATH’)) exit(‘No direct script access allowed’); class MY_Hello extends Hello{ function My_Hello(){ parent::Hello(); } function output(){ return ‘Overwrite Hello World string generated.’; } } ?>
[eluser]sanjoy[/eluser]
Leave it. It Solved. ![]() Thanks everybody for your co-operation.
[eluser]davidbehler[/eluser]
1. Please use the [_code][/_code] tag (remove the underscroes, I only had to add them to stop the forum from parsing them) 2. You want to overwrite the _output function of the controller class, right? Here you go: Create a MY_Controller.php in your application/libraries folder Code: <?php Code: <?php Hope this helps |
Welcome Guest, Not a member yet? Register Sign In |