Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 2 of 2 FirstFirst 1 2
Results 11 to 15 of 15
  1. #11
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Just looked at the Rails example again... it's exactly what ljm was talking about doing - a function set encased in an object architecture.

    It doesn't make sense to use OO in my opinion, unless you're really going OO. If all you're doing is encasing functions, static or otherwise, in a class architecture, you're not doing OO and putting them in a class is pointless.

  2.  

  3. #12
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    I'll give yours a go anyway, I just realised the problem with my own attempt is that I'd have to instantiate the class again and again for each different field, since it only outputs one at a time. Would be all well and good if I wanted a form with one field!

    EDIT: I get fatal errors from your script, about a class not being there (and there isn't one in the script).

  4. #13
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Ah, but see, I find that to be the twisted view of OO that Java's rigid architecture and design forces on you. OO doesn't have to be about using deep class hierarchies to achieve everything -- it can simply be about an object that encapsulates a few useful attributes (in the Rails example's case, the name of the model and the model object itself) and thus eases your code by eliminating repetition (by taking care of ids and names for you based on the above information and extra information you pass it).

    Your example above is a problem only if you're bitterly opposed to mixing the nice structure that helps you repeat yourself less encapsulated in an object with plain old HTML. The form helpers aren't there to do everything for you, they're there to help you to generate form fields for a certain model. If that's not what you're trying to do, then they're inappropriate to your task, and there's no need to use them. And if you're trying to do that in addition to something else, you can write some plain HTML. Again, these helpers are less to make you forget about what code is being generated, and more to try and make you repeat yourself less.

    I keep going back to the Rails architecture because it's beautifully put together, so I'll go there for a second -- you said what if you want to generate a form without a form container. The Rails FormBuilder doesn't add a form container, the encapsulating method [minicode]form_for[/minicode] adds that in, while a similar method, [minicode]fields_for[/minicode] gives you just the field helper methods without adding a form wrapper (usually particularly useful for generating fields for models that compose other models). All your architecture (whatever it may be) has to do is provide an easy way to do most things, and let you grind down to the basics when that fails. Take, again, ActiveRecord, the Rails ORM. It does a whole lot of stuff for you, but when it counts, it lets you grind down to the SQL and build out a blazing fast query, because there's no reason to eliminate the possibility, it's just nice to abstract it away while it's not necessary.

  5. #14
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Quote Originally Posted by ljm
    I get fatal errors from your script, about a class not being there (and there isn't one in the script).
    Here, I fixed it... I had developed the Option subroutine to work with my OO database framework...

    This version will work flawlessly, and has a badass validation tool. Check it out at www.transio.com/forms

  6. #15
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    Cool, thanks

    I didn't really consider all this stuff about logic within the coding. All I wanted to do with my own attempt was create a sort of form abstraction layer, like there is with databases. I've noticed that object oriented code is a lot neater and easier to follow (as long as it is semantic and documented well) than doing things the procedural way (mixing PHP and HTML). My own class would've taken the HTML out of the main script, and put it in the class so it could be reused without me having to code it all again for every site or page. It appears that the usefulness of this is debatable, going off this thread.

    I'll give your script a go though, Transio. If it makes life easier, I'll certainly make use of it a lot more often! What you've done is pretty much what I was trying to do (and nearly had, until I deleted it all). Very helpful!


Page 2 of 2 FirstFirst 1 2

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:17 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com