From: <po...@mi...> - 2004-04-16 16:17:14
|
Hi all. Allow me to add a few comments about the Item and Manager classes. First = of all sorry for my crappy English.=20 About half a year ago I started to develop modules for PHPWS (btw great = CMS, I love it). Just like Mike, thinking in a PHPWS-way almost gives me = constant headache. I'm feeling much better now, but I still have a lot of = unsolved questions about the right way to develop modules in PHPWS. And to clear out any comments regarding "the right way", I just want to mention, that I know there isn't really "a right way", but I'm kind of a standardization freak (working as a Java Architect), and love = frameworks, code reuse, templates, and a standard way of coding. So I tend to spend = a great amount of time on this issue. Rather than just coding modules in my own way, my goal has been to adopt = the PHPWS way of coding and thinking, and to reuse as much "core" code as possible. I agree with Don regarding the use of the Item and Manager classes, and to overcome the lack of documentation, I've looked through = all the mods which make use of these classes, including the Skeleton module. Right now I have a problem with the Item and Manager classes, similar to Mike=92s problem. My current module displays a list of items. Each item = has a related list of items. It looks something like this: Manager (containing item A, B and C) -- Item (B) -- Manager (for item B: = B1, B2 and B3) -- Item (B1) This structure is just like the photoalbum module, where you can have a = lot of albums, and each album can contain a lot of photos. To show the first list, I use the Item and Manager classes. When the = user select an instance (e.g. item B), I need a new Item and Manager = relationship to show the detail list with information limited to the selected main = item. I think this should be done by creating an instance of the Manager class with the ability to limit the selection through a parameterized = constructor, just like in the Item class. Any ideas how to solve the problem the most elegant way? I think (like = Mike) that it's a very simple and common task, which should be, if it=92s not = adding to many disadvantages, taken care of by the standard PHPWS = implementation (no criticism here, just a nice request :-). There is a possibility that the Item and Manager classes already has a = way of dealing with this functionality, and that I have overlooked the implementation. If someone could provide the solution, whether or not I = have to code the solution myself, I would be very grateful. Another problem which has raised when coding my module is the task of validating the user input. If some mandatory information is missing, or = some of the submitted information doesn=92t follow the correct format, the = user must be provided with an error message, and probably the opportunity to correct the input. This is not very easy to generalize, but I think a = lot of module developers would be very grateful, if the Skeleton module could = be extended further with examples of how to solve this task. I have come around the validation in my own module by storing all = submitted variables, doing the validation, and if some error arise, displaying = exactly the same page, including the user input (the last part is very important = for a usability aspect). The Skeleton module (and as far as I know, all of = the other PHPWS mods), throw away the user input, and displays the same = input page, unfortunately empty. One last thing - to all of you thinking about developing your own = modules, don't underestimate the power of the Item and Manager classes, just = because some functionality may be missing. Like Don said, making use of the Item = and Manager classes provides a lot of flexibility and code reuse. My advice = is to spend the time it takes, getting to know how to implement and use = these classes. And to the PHPWS team - thanks for the effort and excellent framework so far. Please keep up the good work. - Michael > -----Oprindelig meddelelse----- > Fra: php...@li... = [mailto:phpwebsite- > dev...@li...] P=E5 vegne af Eloi George > Sendt: 14. april 2004 23:05 > Cc: Php...@li... > Emne: Re: [Phpwebsite-developers] Simple Module >=20 > Right now there's 2 schools of thought on this, Mike. >=20 > The Item-Manager module style came about because we wanted a way for > new module developers to > (1) be able to rapidly develop applications, and > (2) decrease the memory usage of phpWebsite, because many module = classes > were loaded/kept in memory on each pageview. If all of the modules = used > the same base class functions (PHPWS_Manager & PHPWS_Item), then less > code would have to be kept in memory. >=20 > Reason #1 is invalid right now because PHPWS_Manager & PHPWS_Item are > largely undocumented & uncommented. > Reason #2 is partially obsolete because with version 0.9-2, module > classes stopped being automatically loaded by the core, freeing module > developers to more finely tune which classes get loaded when. I said > *partially* because it still has a benefit for modules that operate on > the same page as others. >=20 > The Item-Manager module style also has some limitations -- one being > that you can only take your module's capabilities so far before you = have > to start writing extra code to make the base classes do stuff that > they're not designed to do, 'cause Item&Manager aren't just reuseable > code -- it's an entire framework. The other problem is that when you > have an additional level of middleware code, you also increase the > execution time of the script. When that happens, the server can't > handle as manu requests before it crashes. >=20 > The other method of module writing is like Notes. If you need a = class, > you use one. You write the code to be fast and tight, doing only what > *you* need it to do. You can optimize queries to reduce the workload = on > the database server. It's even easier to learn this way because = either > method requires you to learn how to use the Core classes, but you = really > don't ever have to look at Item or Manager if you don't want to. >=20 > If you want to keep memory usage down, remember that include() and > require() are your friends! If you're not using a piece of code, = don't > load it. Take a look at ArticleManager as a (non-definitive) example. > Also, don't be afraid to unset() a variable after you're finished = using > it -- especially if it's using a lot of memory. >=20 > Bottom line is -- you can decide for yourself which way to want to = code > the module. From your description it sounds so simple that it may not > even need a class! You could most likely code the entire thing in > /mod/yourmodule/index.php and not have your server deal with the > overhead of creating a class. >=20 > Geez, I kinda went off on a rant there, didn't I? > -Eloi- >=20 >=20 > Mike Potvin wrote: >=20 > >Don, > >I guess I'm not thinking in a very PHPWS-way yet :) Help me wrap my = head > >around this. This is how my module works: I have several links to = the > >module in various menus. Each link passes a different parameter (in = this > >case an author's name). The module selects rows from an sql database > that > >match that author's name and displays the results in a table. There = is > no > >user interaction required (user or deity). What would my manager do? > >Mike... > > > > > > > >>Regardless of how simple your module might be, making use of the > >>Item/Manager system provides a lot of flexibility and code re-use. = Even > >>if I just had a single item with a single field (much like = skeleton), I > >>would still use a Manager. > >> > >>Don > >> > >> |