Michael Fesser schreef:
Quote:
it becomes a bit more difficult. You could work with the magic __call()
method to find a helper which implements an ImageList() method. But this
makes the code complicated and hard to debug.
>
You could also have a look at the decorator pattern, which would be a
way to extend the controller functionality by "wrapping" it into another
class, which could be wrapped again into something else if necessary.
This pattern is used for example in the SPL to implement the various
iterators.
Cool im looking into it right now. Seems promising !
Quote:
>
But as said before - it's difficult to give better hints without knowing
the internals of your classes and the way they are intended to work.
Maybe the above contains some useful keywords for further reading.
I understand. The working of the classes is quite simple.
class Controller sets the variables the child class needs and sets the
correct template.
It contains functions like setTemplateName() and getTemplateName()
getMethod() etc.
the child class extends the controller and handles a request
a request to /mypage/index would call class $MyPage->index(). The index
function does not need to contain anything but usually it retrieves the
last couple of entries from a datbase and sends it to the template.
If I would like to make a request to a helper class I would first have
to create a dummy function.
/mypage/uploadimage/10 ->calls $mypage->upladimage();
class MyPage extends Controller{
public function uploadimage(){
new ImageHelper($this);
}
}
The image helper then looks at the Controller variables (Controller =
'MyPage' Action = 'uploadimage' and id = 10) and creates an upload form.
If an image is submitted to this function it handles the image upload
and database interactions.
I think this is quite handy since all i have to do to add image uploads
to any page is add this simple line to the controller.
However I have quite a few of these helper classes and sometimes 90% of
the functions on a page only call a helper class. Nothing really wrong
with that i guess I just had this nagging feeling that i was beeing
silly and that there was a much simple way (there usualy is):-)
Floortje