Welcome Guest, Not a member yet? Register   Sign In
Can we extend our own core classes
#1

[eluser]codeigniterzzz[/eluser]
Basically i have my own controller that extends codeigniter's controller:

class MY_Controller extends CI_Controller


Now my question is can again extend MY_Controller as another core class extension, for example:

class MY_Controllertwo exends MY_Controller


makes sense? In other words i want to another file called MY_Controllertwo which extends MY_Controller. And both are in the application/core folder.
#2

[eluser]LuckyFella73[/eluser]
You can do that.

for example:
MY_Controller extends CI_Controller
-> Frontend_Controller extends MY_Controller
-> Welcome_controller extends Frontend_Controller
-> Admin_Controller extends MY_Controller
-> User_controller extends Admin_Controller
#3

[eluser]codeigniterzzz[/eluser]
[quote author="LuckyFella73" date="1352370366"]You can do that.

for example:
MY_Controller extends CI_Controller
-> Frontend_Controller extends MY_Controller
-> Welcome_controller extends Frontend_Controller
-> Admin_Controller extends MY_Controller
-> User_controller extends Admin_Controller[/quote]

can you show me some code snippets, i get the structure, but where is the Frontend_Controller and all other children controllers located in the application directory for instance? And the naming conventions, do they have to include Controller?
#4

[eluser]LuckyFella73[/eluser]
Code:
<?php


####### in application/core/:
// MY_Controller.php
class MY_Controller extends CI_Controller
{
function __construct()
{
  parent::__construct();

  
}
}

// Frontend_Controller.php
class Frontend_Controller extends MY_Controller
{
function __construct()
{
  parent::__construct();
}
}

// Admin_Controller.php
class Admin_Controller extends MY_Controller
{
function __construct()
{
  parent::__construct();
}
}

####### in your "normal" controllers (application/controller/):
class Controlleraaa extends Frontend_Controller
{

function __construct()
{
  parent::__construct();
  
}
}

// or
class Controllerbbb extends Admin_Controller
{

function __construct()
{
  parent::__construct();
  
}
}
#5

[eluser]boltsabre[/eluser]
I don't mean to be rude codeigniterzzz, but have you:

- Googled this... there are already posts/articles on how to do this.
- Tried it yourself?

If you have 1. Google it and found something, and 2. Tried to implement it but run into some problems, 3. What is the problem? Error messages???

There is nothing better than doing your own research AND trying it yourself, it's amazing what you'll learn, thus speeding up your development time because you'll ultimately know more about CI and how it works, thus reducing your need to ask questions on here and wait for replies.

Apologies in advance if you have done the above mentioned, and if so, please post your code and/or errors.
#6

[eluser]codeigniterzzz[/eluser]
[quote author="boltsabre" date="1352372010"]I don't mean to be rude codeigniterzzz, but have you:

- Googled this... there are already posts/articles on how to do this.
- Tried it yourself?

If you have 1. Google it and found something, and 2. Tried to implement it but run into some problems, 3. What is the problem? Error messages???

There is nothing better than doing your own research AND trying it yourself, it's amazing what you'll learn, thus speeding up your development time because you'll ultimately know more about CI and how it works, thus reducing your need to ask questions on here and wait for replies.

Apologies in advance if you have done the above mentioned, and if so, please post your code and/or errors.[/quote]

well i google it before as well, only thing reason y it didn't work for me is because i didn't realize we had to include Controller in the name of hte controller in core folder. The codeigniter documents don't emphasize that either.

Again thanks a bunch for the snippets.
#7

[eluser]codeigniterzzz[/eluser]
[quote author="LuckyFella73" date="1352371983"]
Code:
<?php


####### in application/core/:
// MY_Controller.php
class MY_Controller extends CI_Controller
{
function __construct()
{
  parent::__construct();

  
}
}

// Frontend_Controller.php
class Frontend_Controller extends MY_Controller
{
function __construct()
{
  parent::__construct();
}
}

// Admin_Controller.php
class Admin_Controller extends MY_Controller
{
function __construct()
{
  parent::__construct();
}
}

####### in your "normal" controllers (application/controller/):
class Controlleraaa extends Frontend_Controller
{

function __construct()
{
  parent::__construct();
  
}
}

// or
class Controllerbbb extends Admin_Controller
{

function __construct()
{
  parent::__construct();
  
}
}
[/quote]

Actually I tried the above scenario, it didn't work for the Frontend_Controller when extending it with a controller in the application/controller file.
#8

[eluser]codeigniterzzz[/eluser]
and also im using codeigniter version 2.1.2, if that makes a difference.
#9

[eluser]Aken[/eluser]
You have to explain more than "it didn't work". Mention specific errors, or what you expected and what actually happened.
#10

[eluser]codeigniterzzz[/eluser]
[quote author="Aken" date="1352417792"]You have to explain more than "it didn't work". Mention specific errors, or what you expected and what actually happened.[/quote]

codeigniter threw the 404 not found error:

404 Page Not Found
The page you requested was not found.

And i checked my routes, the directories the controllers were in, and the name i typed in for the class name of the controller. Basically everything should be where it should be. I also just upgraded to codeigniter 2.1.3 just now.




Theme © iAndrew 2016 - Forum software by © MyBB