Best way to execute actions within a class
| From: | daniel at electroteque dot org | Date: | Fri, 28 Jan 2005 11:14:50 +0000 |
| Subject: | Best way to execute actions within a class | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-207574@lists.php.net to get a copy of this message | ||
I have been building a lightweight PHP4 based, hopefully PHP5 OO structure
where each page or php file contains its own class which is then executed
using the constructor like so
new SomeProject_SomeSubProject();
within the subclasses contructor I then call a method called start which is
in a base class called Page which is extended from the main project class
called SomeProject.
Within start it calls a method to check action page get uri's ie
?action=view , what i used to within procedural code is use switch
statements but seem taxing. Within this now will check if its a get or post
method and execute a method in the class with the same name ie public
function action_view() or if its a post method i have chosen to call it
post_action_view(). Now is this a good setup I would like some feedback on
how people in an OO world would achieve this.
Now that i have started executing constructors within the main page files, I
have come to think of better ways passing around a url possibly like
something like this
someurl/index/someproject_somesubproject/view
or
someurl/someproject_somesubproject/view
or
someurl/index/aliasofclass/view
or
someurl/aliasofclass/view
and for adding keys to the end for db stuff something like
someurl/index/aliasofclass/view?ID=1
or
someurl/index/aliasofclass/view/ID/1
i think then all u need is the main index.php file which works out which
class to load and execute ? And possibly peristist the objects loads too via
shm maybe ?
And if you need other files it could be like
someurl/otherfile/aliasofclass/view/ID/1
I'm sure this is all mod_rewrite stuff, is this taxing to do ?
Let me know always open to suggestions especially ways to do caching better.