Welcome Guest, Not a member yet? Register   Sign In
Subclassing Controller
#11

[eluser]stoefln[/eluser]
why dont you move your controllers to the controller-directory?....
i have not tried it yet but i am pretty shure that should work, -you will have to require_once("Uno.php") in your final controller implementations
#12

[eluser]Mark van der Walle[/eluser]
Indeed you have to require the Uno or Duo classes to be able to extend them. Just a simple

Code:
require_once APPPATH . '/libraries/Uno.php';

class Whatever extends Uno {}
#13

[eluser]taewoo[/eluser]
Thanks. Questions:

1) what is the difference between __construct() and Controller() ? Is one preferred over another?
2) does Uno and Dos need to be in application/library or application/controller directory?
#14

[eluser]Mark van der Walle[/eluser]
1: __construct() is the PHP5 contructor and Controller would be the constructor for the Controller class in PHP4. PHP5 supports the PHP4 version still btw.

See:
http://www.php.net/manual/en/language.oop.php
http://www.php.net/manual/en/language.oop5.php

2: It doesnt matter, but I would put them into the libraries so they cannot be called from the URL.
#15

[eluser]Mirage[/eluser]
1) They both are constructor methods, being called when an instance of a class is created with the 'new' operator. In PHP4 the constructor must be named the same as the class. So for the 'Controller' class 'Controller()' is the constructor. In PHP5 this was extended and you can use the generic __construct() method name as a constructor.

2) Controller directory. The CI Framework automatically includes Controller (core class) and then MY_Controller (core extension) and then the actual controller from the controllers directory.


Cheers,
-m
#16

[eluser]Mark van der Walle[/eluser]
@mirage: He wants to use another level of sub classing. Controller -> MY_Controller -> Uno -> WhateverController. So it would be better to not be able to load the "parent" Uno controller from the URL. You would not want it to be loaded automatically.
#17

[eluser]Mirage[/eluser]
Loading the 'Uno' controller from the URL won't work because then you won't reach your final target the WhateverController.

The core extension 'MY_Controller' is what will be instantiated by CodeIgniter. You can only have one extension. If he needs multiple base controllers he'll have to include them at the top of each controller class.

Cheers,
-m
#18

[eluser]Mark van der Walle[/eluser]
[quote author="Mirage" date="1221072031"]Loading the 'Uno' controller from the URL won't work because then you won't reach your final target the WhateverController.

The core extension 'MY_Controller' is what will be instantiated by CodeIgniter. You can only have one extension. If he needs multiple base controllers he'll have to include them at the top of each controller class.

Cheers,
-m[/quote]

If you read through the posts you will notice that is what I said.

It goes through a few questions about multiple inheritance, how to do that then where to put the files. Smile

My last post was an answer to where to put the parent controllers, which should not be placed into the controller folder because calling them from the URL would be possible then.
#19

[eluser]taewoo[/eluser]
You guys are awesome. Thanks
I'll try both and let you know...




Theme © iAndrew 2016 - Forum software by © MyBB