Welcome Guest, Not a member yet? Register   Sign In
Problem creating a second controller class
#1

[eluser]Unknown[/eluser]
I'm new to MVC, OOP & CodeIgniter and still loving it. I created a basic website using CodeIgniter and all seemed fine until I decided to try to get clever.

I have a page called start.php which contains

Code:
class Start extends Controller {
various properties and methods in here
}

This all works fine.

Then I decided that I want pages grouped together and so decided to copy the page start.php, rename it to services.php and rename the class to
Code:
class Services extends Controller {
various properties and methods in here
}

Now when I try to browse to a page which should serve up the content from the new class, I get the following error message:
Quote:Message: Undefined property: Services::$menu

The message claims that the source of the error is at line 57, which contains this
Code:
$data['menu'] = $this->menu->show_menu();

At the top of the class, I have
Code:
function Start()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->library('menu');
        $this->load->library('menulower');
        $this->load->library('banner');
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css');
        $this->robots = '<meta name="robots" content="index, follow" />';
        
    }

This all works fine for the class Start extends Controller, so I don't understand why it will not work for my new class. Can someone please help.

Thanks
#2

[eluser]Ram2810[/eluser]
See if these are the first few lines of the new controller file

Code:
class Services extends Controller {

   function Services()
   {
      parent::Controller();
   }
.....
.........
#3

[eluser]Unknown[/eluser]
Thanks for that.. It seems I had not given the method/function the correct name. I had left it with the same name copied over from the Start.php class.

Problem solved.
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB