Welcome Guest, Not a member yet? Register   Sign In
Bug v3.1.9 MY_Controller
#1

I define __constructor function inside MY_Controller class extends CI_Controller, just write
Code:
echo 'Hello World'
then I extends it to Home Controller, write index at Home Controller then just run it in my browser. Unfortunately, it just blank, so I try to create public variable in MY_Controller, assign it with a few string through the __constructor, var_dump it through index at Home controller, it just show null, can anybody help me, tks

this is my code 

core/MY_Controller.php

PHP Code:
class MY_Controller extends CI_Controller
{
 
   public $foo;

 
   public function __constuct()
 
   {
 
       parent::__constuct();
 
       
        $this
->foo 'Helloooow';
 
   }


controller/Home.php
PHP Code:
<?php

class Home extends MY_Controller
       
    public 
function index()
 
        
        var_dump
($this->foo );
 
      



the result is null
Reply
#2

It might work better if your constructor was called "__construct" (notice the missing "r"), and the same with the parent one you call?
I trust your base controller is inside the system/core folder.
Reply
#3

Got love those user bugs lol.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(12-18-2018, 09:47 AM)InsiteFX Wrote: Got love those user bugs lol.

yeahhh, it's user bug, lol  Big Grin
Reply
#5

many IDE's clearly show these typing failures. After all, who never went through it. However, we should pay more attention to errors to avoid user bug posts.
keep an eye on the code Wink
Reply




Theme © iAndrew 2016 - Forum software by © MyBB