PHP Classes (extends help)
Posted: Fri Jun 30, 2006 9:41 am
Pimptastic | Please use
Questions:
* I want to access Core and Controller functions from MyPage, should I use parent:: or pass the object references down to MyPage? Passing the objects will get messy because I may have more 'core' objects to pass at a later date.
* If i want to access a public variable in Core do I have to create a function for this? e.g. getSetting();
* If i load another module though Core, so I have Core, Controller and say UrlParser how should I access UrlParser though Controller?
--
I'm still pretty new to OO and I want to do it correctly but finding it hard to find good tutorials/help on these kind of issues so any help would be excellent!
If anyone can point me in the right direction for proper PHP OO design that would be wicked too.
Thanks!
zeen
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Comments on this please:Code: Select all
//---------------------------------
class Core {
var $controller;
function Core() {
//set up controller
$this->controller = new Controller;
}
}
//---------------------------------
class Controller extends Core {
var $page;
function Controller {
//set up mypage class
$this->page = new MyPage;
}
}
//---------------------------------
class MyPage extends Controller {
function MyPage() {
//I want to call functions from controller and core
//should I pass the Core object to Controller then Core and Controller to MyPage
//or use parent::
}
}
//---------------------------------* I want to access Core and Controller functions from MyPage, should I use parent:: or pass the object references down to MyPage? Passing the objects will get messy because I may have more 'core' objects to pass at a later date.
* If i want to access a public variable in Core do I have to create a function for this? e.g. getSetting();
* If i load another module though Core, so I have Core, Controller and say UrlParser how should I access UrlParser though Controller?
--
I'm still pretty new to OO and I want to do it correctly but finding it hard to find good tutorials/help on these kind of issues so any help would be excellent!
If anyone can point me in the right direction for proper PHP OO design that would be wicked too.
Thanks!
zeen
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]