CodeIgniter Forums
Parent Function Inside Controller? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Parent Function Inside Controller? (/showthread.php?tid=25944)

Pages: 1 2


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]Alfredor[/eluser]
Is that possible for example lets say I got the Test controller
controllers/test.php
Code:
<?php
class Test extends Controller{
function Test()
{
parent::Controller();
}

function index()
{
//some code
}

function update()
{
parent::index();
}
}

Is this Possible? :]


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]davidbehler[/eluser]
Do you want to run the index function from the parent controller class or the test class?
Code:
parent::index(); // this runs the index class of the parent controller class
$this->index(); // this runs the index class of your current class, in this case test class



Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]Alfredor[/eluser]
I Mean what If I want to make links like this: (Test Controller as example).
http://example/test/profile/update.
Controller:
Code:
<?php
class Test extends Controller{
function Test()
{
parent::Controller();
}

function index()
{
//some code
}

function profile()
{
//some code
}

function update()
{
parent::profile();
}
}

I Think that could be done with subfolders, but not sure if the original controller will remain working.


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]brianw1975[/eluser]
yes, this should work; however, did you rewrite Controller.php to add the profile function? Or did you mean to use "test extends MyController" and MyController has the profile function in it?

[quote author="Alfredor" date="1262384261"]I Mean what If I want to make links like this: (Test Controller as example).
http://example/test/profile/update.
Controller:
Code:
<?php
class Test extends Controller{
function Test()
{
parent::Controller();
}

function index()
{
//some code
}

function profile()
{
//some code
}

function update()
{
parent::profile();
}
}

I Think that could be done with subfolders, but not sure if the original controller will remain working.[/quote]


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]Alfredor[/eluser]
Absolutely Not :]. Anyways if I do this with subfolers the original controller will work?


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]brianw1975[/eluser]
parent::anything() will call that method from the parent regardless of what you want to do with it, just make sure that anything() actually exists.


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]davidbehler[/eluser]
Do you even know what classes are or what "parent" means?

This has nothing to do with folders or subfolders, it's about a class extending another class.

You might wanna read on OOP with PHP Wink


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]Alfredor[/eluser]
Actually I Don't need the method itself I just need its uri, for naming convention.
cause lets say I have a /site/profiles/ and then I want to call another function called update, so the uri is /site/profiles/update. I though that there most be a way of doing it withing the controller, but I think that making a subfolder would be better, cause I actually don't understand very well the parent stuff.


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]Alfredor[/eluser]
[quote author="waldmeister" date="1262392227"]Do you even know what classes are or what "parent" means?[/quote]

I do.
[quote author="waldmeister" date="1262392227"]
This has nothing to do with folders or subfolders, it's about a class extending another class.[/quote]
I know I just want the uri not the method

[quote author="waldmeister" date="1262392227"]
You might wanna read on OOP with PHP Wink
[/quote]
I read it before I actually posted :]


Parent Function Inside Controller? - El Forum - 01-01-2010

[eluser]brianw1975[/eluser]
wow...... I don't even know how to begin in saying that you are making things so very hard on yourself...

first +10,000 on reading up on OOP

add in a vote for reading the CI user guide

This is going to be blunt:

The problem isn't about classes or extending classes, directories or sub-directories its lack of knowledge about the basic workings of CI and it's built in functionality, plus as you yourself stated, lack of knowledge of OOP functionality.

For this specific problem check out http://ellislab.com/codeigniter/user-guide/general/routing.html

but as I stated above, please, go read the user guide, make many links to it, download it to your ipod touch/iPhone, make a local copy on your PC, etc. it will help you out so much.