ed
Member
Registered: 10th Sep 03
User status: Offline
|
I think I'm making a right hash of this, but there are a few people on here who do PHP right?
I've written a CMS that utilises and object called page, this loads basic stuff into the object as methods and properties of that class - these include stuff like page metadata that doesn't really change from page to page, but is loaded from either a config file or the database. I am trying to load a sub-class to extend this class with page specific information, I call this class application. This sub-class loads items such as the page title and the actual HTML that should be rendered on the page, this is all within a separate php file and the arrangement looks something like this:
code: <?
//page.php
class page{
public function loader(){
//Do stuff
return path/to/applocation.php
}
//Do more stuff here
}
//applocation.php
class application extends page{
public $pageTitle='My OOP Website';
public function pageHTML(){
//Get the page from the database
return $pageHTML;
}
}
//index.php
require_once('page.php');
$page=new page;
require_once($page->loader());
//Then what do I do to extend the class 'page'
?>
So basically index.php loads the class page, it then loads the script with the application class but then I get stuck. What do I actually need to do to extend the page class, do I create a new instance of the application class which will be added to the current instance of page ($page)?
Sorry if it's a bit vague
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
Not much help, but OO is eugh!
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
I like OOP, I think I've been doing too much Javascript and it's broked my head
|
Reedy
Member
Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
|
ed,
Why are you calling page in the index file? all of the attributes, functions from page are inside the application class so you should be calling that.
|
Reedy
Member
Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
|
//index.php
require_once('application.php');
$objApplication=new application;
$objApplication->loader();
If you want to add to the page class then thats fine and the application class will inherit these functions.
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
There are more things in index.php than just the page class, like user authentication e.t.c.
So I call the sub-class before declaring the main class and then it would work?
|
Reedy
Member
Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
|
well if i was doing it, I would probably have an authentication class and make that instantiate in the constructor of the page class.
I dont think calling the subclass will work, I dont quite follow what you are trying to do.
i think the structure should go:
An Application has many pages so one to many.
So the application class shouldnt extend the class, instead should instantiate the page class inside itself.
Does that make sense?
|
Reedy
Member
Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
|
application class
{
$arrPages = array();
public function addPage()
{
$objNewPage =new page;
$this->Pages[] = $objNewPage;
}
}
//something like that, would probably work out better.
[Edited on 16-02-2011 by Reedy]
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
Authentication is kept separate as a lot of stuff is done via AJAX. It's a little bit messy at the moment, but I'm learning it and tidying it all up
I get what you mean about the names, I've called the sub class an application in the sense that you can install a blog app or a media app (etc) into the page. Not sure if it makes sense to do it like that?
|
Reedy
Member
Registered: 11th Apr 04
Location: Hammersmith
User status: Offline
|
if you have time to, i would suggest you use a strict framework like Kohana, its a modification of the mvc framework but it has a shed load of helper tools and its very structual making your code and files very tidy.
|