Get variables created in MY_Controller? |
[eluser]chefnelone[/eluser]
hello I created MY_Controller and defined some variable in it. Now, I don't know how to recover these variables from another controller which is extended to MY_Controller. MY_Controller.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Code: <?php if (! defined('BASEPATH')) exit('No direct script access');
[eluser]n0xie[/eluser]
Make them class properties: Code: class MY_Controller extends Controller{ Then in your extended class: Code: function index() Although in this case where you have to deal with 'global config' settings, you might be better off putting it in the config array or load it from the database.
[eluser]chefnelone[/eluser]
[quote author="n0xie" date="1268178777"]Make them class properties: Code: class MY_Controller extends Controller{ Then in your extended class: Code: function index() Although in this case where you have to deal with 'global config' settings, you might be better off putting it in the config array or load it from the database.[/quote] It did't work. I get a blank page. If I remove the word 'protected' it runs fine, but I can't get the value of $company_email though; Code: class MY_Controller extends Controller{ extended class: Code: function index() then I get this error message: Code: A PHP Error was encountered
[eluser]InsiteFX[/eluser]
Your constructor is wrong CodeIgniter's core is PHP4 When you extend the MY_Controller then you can use PHP5 constructor. Code: class MY_Controller extends Controller{ Enjoy InsiteFX
[eluser]chefnelone[/eluser]
ok, I think the constructor is ok now? How do I get the value of $company_email from others controllers? this is still not working Code: function index() Code: A PHP Error was encountered
[eluser]n0xie[/eluser]
If you use PHP4 try this: Code: class MY_Controller extends Controller{
[eluser]chefnelone[/eluser]
I get the same error message: Message: Undefined variable: company_email
[eluser]n0xie[/eluser]
Show us your entire code. I can't guess what's going wrong.
[eluser]chefnelone[/eluser]
I get this error: Code: A PHP Error was encountered if I run this code: application/libraries/MY_Controller.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); application/controller/mycontroller.php Code: <?php application/views/myview.php Code: <?php echo $company_email; ?>
[eluser]n0xie[/eluser]
Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
Welcome Guest, Not a member yet? Register Sign In |