SitePoint Sponsor

User Tag List

Page 1 of 4 1234 LastLast
Results 1 to 25 of 99
  1. #1
    Massimiliano Bruno Giordano sid egg's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What classes do you use in ALL your OO-projects.

    What classes do you reuse the most? Which do you find the most useful? Why? etc...

    I use my:

    Templating Class,
    Form Classes (1 for each element, a form (which has an overloaded render() function) and some form-design classes which overload the render() element)
    Database Classes (SQLConnect, SQLStatement, SQLResult)
    Request Class (basically, safely reads $_POST, $_GET, etc)
    Errors Class (simple, just handles and "recieves" errors)

    You?
    GamesLib.com - the slickest, most complete and
    easily navigatible flash games site on the web.

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Can I see your Request Class?
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Norway - Oslo
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All my current projects (work and private) are mixed oop/procedural so theres really not that many classes i reuse all of the time.
    What i always use is db-abstraction and templating, which i think recently i have found some i'm happy with.
    And i've made a debugclass at work that we use everywhere now, which i will bring to my personal projects aswell.

    Im planning to write a small RBAC-implementation in the near future aswell which i plan to use in all projects where i need any kind of "users".

    Hopefully in 6 months or so i use pure OOP on all personal projects bigger than echo "hello world"; then i guess i could answer this more correctly

  4. #4
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    'Fraid I'm not going to be posting any more script to these forums, better just not to ask why...

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Norway - Oslo
    Posts
    198
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    'Fraid I'm not going to be posting any more script to these forums, better just not to ask why...
    Uhm, as far as i can see no one asked you to post a script either, just about what classes you normaly use

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True, I wasn't asked personally but I was referring not to this particular thread, but to the forums yes?

    to these forums,
    Just thought I'd say so, just happened to be this thread, that's all

  7. #7
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A URL class, for breaking apart and putting back together URLs. Useful for subclassing for transparently adding query parameters.

    Most of database classes have become redundant since moved to PDO / PHP5, that does connections, prepared statements, result iterators.
    An adaptor for PDOStatement to SeekableIterator pretty replaces all that, for common applications.

  8. #8
    Massimiliano Bruno Giordano sid egg's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by The New Guy
    Can I see your Request Class?
    It's fairly simple, you could recreate it in minutes, basically, it works like this (I don't want to go find the files and stuff right now, sorta busy)
    PHP Code:
    $request = new Request("variable"/* [optional] (can be GET, POST, COOKIE, SESSION or VALUE (if it is VALUE, the first parameter is treated as the value of the $request object)-> */ "GET");
    $request->rules "^(.*)+$"// or, $request->rules = $request->getURLRules(); // lots of predefined rules!
    $value =$request->value(); 
    GamesLib.com - the slickest, most complete and
    easily navigatible flash games site on the web.

  9. #9
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most of database classes have become redundant since moved to PDO / PHP5, that does connections, prepared statements, result iterators.


    You either the option of PDO or Creole. At the moment Creole has the advantage of more documentation, and partnering up with Propel... But we should be able to use Propel with PDO easily?

    As for adapting PDO, I'd be interested in knowing what you have in mind

  10. #10
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=Dr Livingston]

    You either the option of PDO or Creole.
    [QUOTE]

    Not looked at Creole or Propel. Just glimpsed at the docs of Creole, and it seems rather dependant on dynamically building SQL, with the Criteria class.
    Which I'm not a fan of, probably as Im a stored proc junky, and things like table join orders, and ordering of conditions can be quite significant on query execution speed.

    Still exploring what can be done with PDO atm.
    The few generic classes I've written for it, is PDOTransaction which counts the number of open transactions, and rolls back any open at __destruct time.

    The other is just to hide the fact that PDO is being used to the callee

    Code:
        $stmt = $this->pdo->prepare('SELECT categoryID, name FROM Categories WHERE name LIKE ? ORDER BY name ASC');
        $stmt->bindParam(1, $name, PDO_PARAM_STR);
        $r = $stmt->execute();
        $stmt->setFetchMode(PDO_FETCH_CLASS, 'Category');
        return new PDOStatementIterator($stmt);
    So the return value is an Iterator over a set of objects of class 'Category'.

    Bit disappointed PDO_FETCH_FUNC fetch mode is limited just for PDOStatement::fetchAll() usage, would've been neater to have it call a factory method for each row.

  11. #11
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Pattaya
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My most frequent are:

    1) A database class. I have one for MySQL, AND one for PostregeSQL, where the use can use the same syntax for both, so nothing in the source codes have to change if thy switch DB systems... $db->query("SELECT * FROM somewhere");

    2) A function library. This contains all sorts of functions, such as an email function, functions to manipulate strings (Blah blah.....blah blah), crete random strings, set and adjust cookies

    3) A databank class. This contains arrays of all sorts of information, ISO codes to Countries, US state names, anything else that needs to by used dynamically in select menus and have a certain option selected and whatnot, or if I need a certain value printed on the page from say - a cookie or DB entry. If the value is 'TH', the function would print "Thailand". Very useful.

    4) Date menus! If the same site needs date selection menus in multiple places, this is very useful. It allows to choose if the "date" field is to be included, and which direction to set the years, and by how many. A historical search would need dates, and years going back 15 years, but a credit card checkout field would not require dates, but the years would have to be ahead by 10.

    5) Errors. I have a special class for both user-input errors an to log any PHP warnings and such.

    -Hobgoblin

  12. #12
    Massimiliano Bruno Giordano sid egg's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hobgoblin
    3) A databank class. This contains arrays of all sorts of information, ISO codes to Countries, US state names, anything else that needs to by used dynamically in select menus and have a certain option selected and whatnot, or if I need a certain value printed on the page from say - a cookie or DB entry. If the value is 'TH', the function would print "Thailand". Very useful.

    4) Date menus! If the same site needs date selection menus in multiple places, this is very useful. It allows to choose if the "date" field is to be included, and which direction to set the years, and by how many. A historical search would need dates, and years going back 15 years, but a credit card checkout field would not require dates, but the years would have to be ahead by 10.

    -Hobgoblin
    Aye! I forgot that one! class.Lists.php! $frm = new FormSelectBox("cntry", "Select Your Country", Lists::getCountryList());
    [my country/provice/state lists seem to wrok identically to yours]
    :-)

    What else do you have in your lists file? I have country list, province list (Canada), States list (US) and Open-Source Licenses List (leftover from an old project, figured I'd keep it :P -- no I won't share it, sorry -- it's very extensive, and it took me a long time to create)

    As to #4, what does that mean :P? Some examples please?
    GamesLib.com - the slickest, most complete and
    easily navigatible flash games site on the web.

  13. #13
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mine are just input handling, database abstraction, debug, and paging.

  14. #14
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Middle Earth
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use logging class a lot besides sql classes.

  15. #15
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Pattaya
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sid egg
    As to #4, what does that mean :P? Some examples please?
    I suppose it's easier to post the whole thing than to try and explain it

    PHP Code:
    class whatever()
    {

        
    /*---- SNIP  ------*/

        
    function month_list()
        {
            
    $months = array(
                
    "January"    => "1",
                
    "February"    => "2",
                
    "March"    => "3",
                
    "April"    => "4",
                
    "May"        => "5",
                
    "June"    => "6",
                
    "July"    => "7",
                
    "August"    => "8",
                
    "September"    => "9",
                
    "October"    => "10",
                
    "November"    => "11",
                
    "December"    => "12",
                );

            return 
    $months;
        }

        function 
    day_list()
        {
            
    $days = array();

            for (
    $m 1$m <= 31$m++)
            {
                
    $days[] = $m;
            }

            return 
    $days;
        }

        function 
    year_list($back$ahead)
        {
            
    $this_year date("Y");

            
    $years = array();

            for (
    $y $this_year $back$y <= ($this_year $ahead); $y++)
            {
                
    $years[] = $y;
            }

            return 
    $years;
        }

        function 
    date_dropdowns($select_field_name=""$select_time=""$use_days=1$years_back=2$years_ahead=1)
        {
            if (
    $select_time != "")
            {
                
    $sel_month date("F"$select_time);
                
    $sel_date  date("d"$select_time);
                
    $sel_year  date("Y"$select_time);
            }

            
    $this->datelist "<select name='";

            if (
    $select_field_name !="")
            {
                
    $this->datelist .= $select_field_name "_";
            }

            
    $this->datelist .= "month'>";

            foreach (
    $this->month_list() as $k => $v)
            {
                
    $this->datelist .= "<option value='" $v "'";

                if (
    $sel_month == $k)
                {
                    
    $this->datelist .= " selected='selected'";
                }

                
    $this->datelist .= ">" $k "</option>";
            }

            
    $this->datelist .= "</select>&nbsp;<select name='";


            if (
    $use_days == 1)
            {

                if (
    $select_field_name !="")
                {
                    
    $this->datelist .= $select_field_name "_";
                }

                
    $this->datelist .= "day'>";

                foreach (
    $this->day_list() as $k)
                {
                    
    $this->datelist .= "<option value='";

                    if (
    $k 10)
                    {
                        
    $this->datelist .= "0";
                    }

                    
    $this->datelist .= $k "'";

                    if (
    $sel_date == $k)
                    {
                        
    $this->datelist .= " selected='selected'";
                    }

                    
    $this->datelist .= ">" $k "</option>";
                }

                
    $this->datelist .= "</select>&nbsp;<select name='";
            }

            if (
    $select_field_name !="")
            {
                
    $this->datelist .= $select_field_name "_";
            }
            

            
    $this->datelist .= "year'>";

            foreach (
    $this->year_list($years_back$years_ahead) as $k)
            {
                
    $this->datelist .= "<option value='" $k "'";

                if (
    $sel_year == $k)
                {
                    
    $this->datelist .= " selected='selected'";
                }

                
    $this->datelist .= ">" $k "</option>";
            }

            
    $this->datelist .= "</select>";

            return 
    $this->datelist;
        }


  16. #16
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Southwest US
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Other than the normal db, form, email, and templating class...

    1. I have a class which handles storing/retrieving hierarchical data. I created it about three to four months ago for a project I was doing. Since then, for unknown reasons, I have been getting projects which utilize it. (It really needs to be re-written since I was just learning OOP at that time )

    2. I am now putting the finishing touches on a file system class, to create/delete directories/files, read/write files, and create/read zip files. After that is finished I have plans to create a handling class based off of my db class so that I can have a kind of file based db class. (I'm not sure how useful this will be but it seemed like a good challenge.)

    Thanks for listening,
    Itshim

  17. #17
    Massimiliano Bruno Giordano sid egg's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Itshim
    Other than the normal db, form, email, and templating class...

    1. I have a class which handles storing/retrieving hierarchical data. I created it about three to four months ago for a project I was doing. Since then, for unknown reasons, I have been getting projects which utilize it. (It really needs to be re-written since I was just learning OOP at that time )

    2. I am now putting the finishing touches on a file system class, to create/delete directories/files, read/write files, and create/read zip files. After that is finished I have plans to create a handling class based off of my db class so that I can have a kind of file based db class. (I'm not sure how useful this will be but it seemed like a good challenge.)

    Thanks for listening,
    Itshim
    Wow, those sound great, interested in sharing them?
    GamesLib.com - the slickest, most complete and
    easily navigatible flash games site on the web.

  18. #18
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Southwest US
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As for the file system class; it is not finished yet…

    I just want to warn you:
    The hierarchical data class is based on the recursion method, which isn’t all that great; in fact this method has been described as slow and inefficient for large trees (hence one of the major reasons for it to be re-written). If you are unfamiliar with this method a great tutorial can be found here at sitepoint.

    It will take some time for me to clean it up and create easily understood documentation, which I need to do anyway. Let me know if you still want it.

    Thanks for the interest,
    Itshim

  19. #19
    Massimiliano Bruno Giordano sid egg's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Itshim
    As for the file system class; it is not finished yet…

    I just want to warn you:
    The hierarchical data class is based on the recursion method, which isn’t all that great; in fact this method has been described as slow and inefficient for large trees (hence one of the major reasons for it to be re-written). If you are unfamiliar with this method a great tutorial can be found here at sitepoint.

    It will take some time for me to clean it up and create easily understood documentation, which I need to do anyway. Let me know if you still want it.

    Thanks for the interest,
    Itshim
    I am definately still interested, more, just to look at than anything, but i am sure lots of people here would like it!
    GamesLib.com - the slickest, most complete and
    easily navigatible flash games site on the web.

  20. #20
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Southwest US
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give me some time; it is on its way...

  21. #21
    ¿uʍop ǝpısdn ʎɥʍ velocd's Avatar
    Join Date
    Aug 2002
    Location
    California
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mostly:

    1. DAL Class
    2. DAL::ErrorHandling Class (logs DB errors, sends emails, etc.)
    3. Template Class
    4. User Class (authentication functions, privilege handling, etc).

    Recently I've extended the template class for my job to support "on-the-fly" dynamic handling of form requests (POST & GET), using XMLHttpRequest. Lots of intricate Javascript and DOM handling involved in it. The eval() function of Javascript makes it particularly easy though, by echo()ing Javascript in my methods. It's made our forms more effective to use on an end-user standpoint (less redirects and refreshes), plus quicker to code.. ironically. While our public forms are still former style, the interfaces that most our employees use (whose computers are all under Firefox) will be using XMLHttpRequest methods.

    Template class also handles regex comparisons and replaces for input fields, so to say if somebody entered an invalid SSN the page doesn't process the query, and instead reports the error next to the input field. Regex replacements come in handy also, for if an SSN is entered as xxxxxxxxx the script replaces it as xxx-xx-xxxx prior to insert in the DB. Most handy with currencies and converting dates into MySQL date format also. All this seamlessly done with XMLHttpRequest ;-)

    Although somewhat off-topic, if you haven't messed with XMLHttpRequest (in conjunction with Javascript DOM) you should. It's really awesome.

    (I must also mention replacing any drop down menus that have huge lists of results, like from a query, with an XMLHttpRequest autocomplete input box is definitely the way to go. Much faster execution/render times of pages.)
    Last edited by velocd; Mar 29, 2005 at 07:54.

  22. #22
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    class context (input validation, and output)
    class template (template)
    class dbconnection (database)
    The above are the most common, but boring. More interesting is:
    class utf8_string (filtering, generating UTF8 strings)
    class specialurl (for friendly URLs)
    class debug (for logging errors, profiling etc)
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog · Twitter · Contact me
    Neon Javascript Framework · Jokes · Android stuff

  23. #23
    Massimiliano Bruno Giordano sid egg's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by velocd

    Although somewhat off-topic, if you haven't messed with XMLHttpRequest (in conjunction with Javascript DOM) you should. It's really awesome.

    (I must also mention replacing any drop down menus that have huge lists of results, like from a query, with an XMLHttpRequest autocomplete input box is definitely the way to go. Much faster execution/render times of pages.)
    Would love to, however, I blow at Javascript :P
    GamesLib.com - the slickest, most complete and
    easily navigatible flash games site on the web.

  24. #24
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd be utterly lost without these classes.

  25. #25
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Useful classes for you are

    * Database
    * Logging
    * GD
    * Templating
    * Error Handling/Exceptions
    * Web Services
    * Hierarchacal Data Traversing
    * File/Directory IO
    ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •