SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 58
  1. #26
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fascinating points from CaptainProton and killdash9. Just answering this one quickly;

    Just to make sure I'm understanding you correctly, would it be correct to say that a class is basically a module, a multi-use code snippet?
    Basically yes. If you've ever defined your own PHP function to make life easier for yourself, classes can be regarded as the next step up - a group of functions organised nicely.

    But it's important to remember that classes are a whole lot more than that and their true power is in how they interact - object orientation.

    First step though is to try writing your own simple class. Pick a problem you have to deal with frequently - for example validating use input e.g.;

    PHP Code:
    class Validator {
        function 
    vEmail ($email) {
            
    // Validate $email using reg_exp
        
    }

        function 
    vPassword ($password,$confirm) {
            
    // Validate $password and check it matches $confirm
        
    }

        function 
    vUrl ($url) {
            
    // Validate a URL here
        
    }

    You can then use that from your normal code every time you need to validate one of those;

    PHP Code:
    $myemail="hfuecks@pinkgoblin.com";

    $v=& new Validator;

    if (!
    $v->vEmail($myemail))
        
    trigger_error('Invalid Email!'); 

  2. #27
    SitePoint Enthusiast Digital.Knight's Avatar
    Join Date
    Jun 2002
    Location
    Canada
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by HarryF
    Basically yes. If you've ever defined your own PHP function to make life easier for yourself, classes can be regarded as the next step up - a group of functions organised nicely.
    Oki I'm in the zone on this one now... The combination of the simple description you gave and your 'form validator' class example really painted a crystal clear picture for me.

    Thanx for your help.
    Last edited by Digital.Knight; Oct 12, 2002 at 23:43.
    Cheers...
    -Brian

  3. #28
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another thing to think about, is that you dont want to overload a class. you a class should handle one thing, and handle it well, like any physical tool, it does one thing: a screw driver turns screws, it doesnt measure angles, or hammer nails.

    so instead of making one class that does all sorts of things to all sorts of data, you should make a class that handles one type of data, and does usefull things with it.

    ofcourse it is all just a matter of taste, I suppose, but I think this to be the essence of OOP.

    for example:
    PHP Code:
    class Email {
        var 
    $data;
        function 
    Email$address ) {
            
    $this->data $address;
        }

        function 
    validate() {
            
    // validation code
        
    }

        function 
    value() {
            
    // format and return data
        
    }

        function 
    show() {
            
    // show formated data, eg:
            
    print( $this->value() );
        }

        function 
    sendto$from$subject$body ) {
            
    mail$this->data$subject$body"From: " $from );

    Web Hound
    $x='010000010110001101101001011001000101001001100101011010010110011101101110';
    for($i=0;$i<strlen($x);$i+=8)print(chr(bindec(substr($x,$i,8))));

  4. #29
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is something I whipped up a couple weeks ago, took me about an hour:
    the base class
    the example
    Web Hound
    $x='010000010110001101101001011001000101001001100101011010010110011101101110';
    for($i=0;$i<strlen($x);$i+=8)print(chr(bindec(substr($x,$i,8))));

  5. #30
    killall -9 lusers
    Join Date
    Oct 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems to me that that template engine kind of misses the point of _not_ having to use a syntax other than PHP.

  6. #31
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Linking Problems

    Hello, i followed all the posts/topics about templates very carefully, and have learned very much about it, but i have a problem i can not solve:


    Let us assume we have the following dir structure (nice eh? )

    ROOT
    |_____CLASSES
    | |· template.php
    | |· datatbase.php
    |
    |_____TEMPLATES
    | |· template01.tpl
    | |· template02.tpl
    | |
    | |__IMAGES
    | | · pic1.gif
    | | · pic2.gif
    |
    | · index.php

    Okey, i include the class in index.php the class read in a template from the folder templates and parse it...no problem, but the images which where defined in the template files will not be shown, which is clear because index.php was read in in ROOT and not in TEMPLATES, so there is no folder called IMAGES in ROOT, so it can not work !

    All the templates which was described in this forum, except such template engines like Smarty or FastTemplate etc, do not work with this example. But i dont want to learn the
    spefic syntax of this template engines so i wanted to write
    one at my own, with all the hints from this forum.

    So here is the simple question: How can i solve this problem ?! Any ideas ?!

    Thanks in advance!


    PS: Nice board, i learned very much about PHP!

    And don't blame me for my english, i'm non-english!

  7. #32
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow!

    ROOT
    |_____CLASSES
    | |· template.php
    | |· datatbase.php
    |
    |_____TEMPLATES
    | |· template01.tpl
    | |· template02.tpl
    | |
    | |__IMAGES
    | | · pic1.gif
    | | · pic2.gif
    |
    | · index.php
    How long did that take you?

    My solution to your problem is don't use templates (use object oriented widgets instead). So I'll have to pass...

  8. #33
    SitePoint Enthusiast Digital.Knight's Avatar
    Join Date
    Jun 2002
    Location
    Canada
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by AcidReign
    another thing to think about, is that you dont want to overload a class. a class should handle one thing, and handle it well, like any physical tool, it does one thing: a screw driver turns screws, it doesnt measure angles, or hammer nails.
    Thanks for sharing your advice... I found your illustration to be quite an effective tool in helping me to understand your point more thoroughly!


    this is something I whipped up a couple weeks ago, took me about an hour:
    the base class
    the example
    Excellent!!! Thanks, I'm sure this will really help me a lot in understanding classes better.

    I really have to say that I'm quite impressed with the teaching methods both Harry and yourself have employed here. Neither of you made any attempt to impress me with big and intelligent sounding words or phrases. Instead, with the use of simple 'examples' and 'illustrations', you both successfully helped me pick up on what you were trying to get across. To me this speaks volumes towards your effectiveness as teachers. Excellent job, the both of you!
    Cheers...
    -Brian

  9. #34
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Neither of you made any attempt to impress me with big and intelligent sounding words or phrases.
    That's my job...

    I like to moan about class inheritance, object composition combined with polymorphism and overriding methods to achieve complex tasks with little code.

    Vincent

  10. #35
    Fully Qualified Fool :) luke-innovative's Avatar
    Join Date
    Jun 2002
    Location
    Kent, UK
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's my job...

    I like to moan about class inheritance, object composition combined with polymorphism and overriding methods to achieve complex tasks with little code.

    Vincent
    ..And thats why we love ya
    Luke
    Luke-Martin.com (work in progress) :: Independent Web Designer's Portal
    Freelance Forums :: Sign Up Here
    "What happens if you get scared half to death twice?"

  11. #36
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's great to hear that all this finger exercise is helping people and thanks for saying so.

    Vincent and AcidReign have done an awesome job raising the standards of PHP development on these forums (I just repeat what they say most of the time).

    Now all we need to do is encourage them to write for Sitepoint

  12. #37
    Fully Qualified Fool :) luke-innovative's Avatar
    Join Date
    Jun 2002
    Location
    Kent, UK
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    Thats an idea!

    Vincent, why do you not write for SP, I'm sure you have been asked before, I think people would benefit a lot from hearing from you


    BTW - Thanks to anyone thats helped me clarify some stuff directly or indirectly, appreciated
    Luke
    Luke-Martin.com (work in progress) :: Independent Web Designer's Portal
    Freelance Forums :: Sign Up Here
    "What happens if you get scared half to death twice?"

  13. #38
    SitePoint Enthusiast Digital.Knight's Avatar
    Join Date
    Jun 2002
    Location
    Canada
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by voostind
    That's my job...

    I like to moan about class inheritance, object composition combined with polymorphism and overriding methods to achieve complex tasks with little code.

    Vincent
    So let me get this straight... you like to "moan" about the relationship between an object oriented class and a more general class that it's based on(it's parent class), the composition of an object combined with the ability to treat any object in a generic manner to invoke a behavior on existing classes and any new classes you define in the future and taking advantage of scope modifiers which allow you to retain super and sub classes with the same designation, all to achieve as much complexity with the least amount of coding as possible.

    Am I understanding you correctly?
    Last edited by Digital.Knight; Oct 13, 2002 at 15:26.
    Cheers...
    -Brian

  14. #39
    SitePoint Enthusiast Digital.Knight's Avatar
    Join Date
    Jun 2002
    Location
    Canada
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by HarryF
    I Vincent and AcidReign have done an awesome job raising the standards of PHP development on these forums (I just repeat what they say most of the time). [
    Well Harry, if there wasn't someone to teach how would we ever learn anything... whether it be from a book or on a forum like sitepoint we all learn from somone else!

    Now all we need to do is encourage them to write for Sitepoint
    Sounds like a good idea... Vincent spread the moans a little, write for sitepoint!
    Last edited by Digital.Knight; Oct 13, 2002 at 15:36.
    Cheers...
    -Brian

  15. #40
    killall -9 lusers
    Join Date
    Oct 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Linking Problems

    Originally posted by saik
    [B]Hello, i followed all the posts/topics about templates very carefully, and have learned very much about it, but i have a problem i can not solve:


    Let us assume we have the following dir structure (nice eh? )

    ROOT
    |_____CLASSES
    | |· template.php
    | |· datatbase.php
    |
    |_____TEMPLATES
    | |· template01.tpl
    | |· template02.tpl
    | |
    | |__IMAGES
    | | · pic1.gif
    | | · pic2.gif
    |
    | · index.php

    Okey, i include the class in index.php the class read in a template from the folder templates and parse it...no problem, but the images which where defined in the template files will not be shown, which is clear because index.php was read in in ROOT and not in TEMPLATES, so there is no folder called IMAGES in ROOT, so it can not work !

    All the templates which was described in this forum, except such template engines like Smarty or FastTemplate etc, do not work with this example. But i dont want to learn the
    spefic syntax of this template engines so i wanted to write
    one at my own, with all the hints from this forum.

    So here is the simple question: How can i solve this problem ?! Any ideas ?!
    The simple solution to this problem is to make all of your image URLs relative to the site root. That way the images will display fine both when working on the template and when calling the template from another file. Basicly, instead of <img src="images/image1.gif" /> use <img src="/templates/images/image1.gif" />.

  16. #41
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On a side-note, what does =& do ?
    I've seen it used in this situation only:
    PHP Code:
    $foo =& new bar(); 
    What difference does it have with a simple equal sign ?
    [blogger: zengun] [blogware contributor: wordpress]

  17. #42
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  18. #43
    SitePoint Zealot marcoBR's Avatar
    Join Date
    Jun 2002
    Location
    Brazil
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  19. #44
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by HarryF
    But the point is, how do you design an application?
    It depends on the size of the application. The bigger it is, the more important your design methods will be.

    Do you start with the user interface (the HTML) - draw all the pages users will see, then put the code/database behind them? This is probably what alot of web developers do?

    Or do you start with the database, putting together a database structure then from there, write the code on top and finally the user interface?
    Starting with databases is generally a bad way to design an application. The more tables that you have in your application, the less usable your user interface will be.

    There is a java framework based on this principle called Naked Objects. I dealt with this philosophy in a couple of large systems and it results in software that is very hard to use. (Its no fun to be responsible for software that is considered hard to use.)

    Larry Constantine has an article describing some of the problems with naked objects.

    Or do you even start somewhere in the middle - code first then database and user interface as you need them?
    Or do you start with the simplest thing first? Perhaps you might do the most difficult or the most risky thing first.

    Another approach is to do that which is most important to your customer first. (Contrary to a lot of developers wishes, this is probably NOT "implement a really elegant template language.")

    I tend to favor doing the feature most important to the customer first, ironing out anything difficult or risky as soon as I can.

    I favor a user oriented, task oriented design process. Let me explain.

    First an analogy to explain user interface design:

    Think about how your house is organized. Your house is generally divided into workareas which correspond to the general tasks you perform in your life. You have a kitchen for preparing food, a bedroom for sleeping, a living room for entertainment, etc.

    In each of these workareas, you have gathered the tools and materials necessary for the tasks that you want to perform there. Your house would be virtually unusable if your pans were in the bedroom and your alarm clock was in your kitchen.

    When you are in each workarea, you are assuming a role (such as cook or sleeper). There are generally several interrelated tasks performed in each work area using the same tools and materials that depends on your role at the time.

    Now to extend that to software...

    Software exists to perform a set of tasks. Those tasks can be organized by who does them and when (Roles). Work areas are created to support roles and tasks in the form of web pages (or windows in more traditional software). The workareas (web pages) should contain the tools (commands) and materials (data) necessary to perform those tasks.

    A good user interface design is organized so that everything that you will need for the task is available in a single workarea dedicated to that task, and related tasks.

    So here is an design walkthrough of a very small project I did recently from the perspective of this approach.

    My client wanted an "of the day" type script. He told me It had to perform the following tasks:

    Prominently display todays item.
    Prominently display a small preview of tomorrows item.
    Show a small list of the past weeks items.
    Schedule items to be shown at a specific future date.
    Recycle older items if no new item was available for a given day.

    I wrote these tasks down.

    I silently added the following tasks, which he did not specifically mention:

    Enter a new item.
    Remove an item.
    Edit an item.
    View a list of items.
    View detail about an item.

    I did not write these down because the system was so small. In a larger system I would have made a complete list.

    I identified the two obvious roles: Visitor and administrator. This meant two different workareas in the user interface. This was done in my head. I have worked on larger systems where certain roles were very hard to identify.

    I identified the "Display todays item" as the task most important to my client. I started working on that one first. I simply hard coded the necessary data values into the program and built a template to accept the data values. Then, I designed a database and hooked that up to my code.

    I felt that the Recycling task was the most difficult (because of the date math) and did that next, then display tommorrows item, then display the past weeks items.

    I completed the entire "Visitor" role before even beginning on the "administrator" role.

    I identified the "schedule item" task as most important for the administrator, but did the "enter a new item" first as a pre-requisite. I then did the "view a list" task. I added a an "enter new" link at the top of this list. The list became the central page (workarea) for the administration role. I then added a "delete," "edit," and "View detail" link for each item displayed.

    Next, I went back and added a preview capability to the "add, edit, and delete" functions. This prevented the need for the administrator having to switch between workareas to perform these tasks.

    I uploaded the script to the clients server and demonstrated it to him. During this phase, I realized that I had missed an important task:

    Enter several items one after another.

    I re-worked the add item page to allow the user to specify if they want to add another item or if they wanted to return to the main page (the list).

    After uploading and demonstrating the final version, my client complimented me on how easy the script was to use and how nice it looked.

    The workarea, materials, and tools terminology was coined by Larry Constantine in his book Software for Use.

    What I call tasks are called use cases in the software engineering literature. What I call roles are called actors. (The unfortunately confusing terms use case and actor were coined by the Swedish author Ivar Jacobson in his book Object Oriented Software Engineering.)

    Sorry if I wandered too far off topic or for too long.

    Oh, Somewhere I have a summary of Constantine's UI based design method that I wrote for a class that I taught. If anyone is interested, I can probably post it.

  20. #45
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, Now for the on topic post

    There seem to be three template Philosophies:

    [list=1][*]PHP IS a template Language

    voostind argues well for this approach.
    [*]Separate Presentation Logic From Application Logic

    This is the Smarty camp.
    [*]Separate PHP from HTML

    This is the PHPLIB approach.
    [/list=1]

    I prefer the 3rd approach. Concentrate on separating the PHP from the HTML.

    Its non-programmer friendly. Its dreamweaver friendly.

    It is much easier and clearer to separate the PHP and HTML than it is to separate the application logic and the presentation logic.

    This separation does make certain kinds of changes easier.

    I realize and accept that not every type of presentation change can be made without programming.

    In my experience, with smarty or mixed PHP / HTML, my clients make me do ALL changes. With the PHPLIB approach they seem more comfortable making changes themselves.

  21. #46
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There seem to be three template Philosophies:
    1. PHP IS a template Language
    2. Separate Presentation Logic From Application Logic
    3. Separate PHP from HTML
    I don't think these are separate philosophies. For example, I believe PHP is a template engine, but I also separate presentation logic from application logic. In the HTML I use only some simple PHP to drive the layout, nothing more.

    Vincent

  22. #47
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As a developer and designer I will say that there is little need for a designer to touch the html output that php generates.

    As a developer, if I simply make sure that I apply css classes to elements that may need controlling in the design stage, then I can worry about the css later.

    With css, colaboration between designer and developer have never been easier.

    Here's a common table output that I use
    Code:
    <table class='products'>
      <tr>
        <th>Product Title</th><th>Stock</th><th>Price</th>
      </tr>
      <tr class='odd'>
        <td>Purple Shrooms</td><td>325</td><td>$5.00</td>
      </tr>
      <tr class='even'>
        <td>Green Ganja</td><td>210</td><td>$10.00</td>
      </tr>
    </table>
    In the design stage, I come in and control the table properties such as table padding, margins, cell padding, cell margins, etc etc....

    For this particular table I would do something like this...
    Code:
    table.products {
        border-collapse: collapse;
        width: 100%;
    }
    
    table.products td, th {
        text-align: left;
        padding: 5px;
        height: 32px;
        border: 1px solid #efe;
    }
    
    table.products th {
         background-color: #000;
         color: #fff;
    }
    
    table.products td {
        font-size: 0.7em;
        font-weight: bold;
    }
    
    table.products tr.odd {
        background-color: #fff;
    }
    
    table.products tr.even {
        background-color: #efe;
    }
    In essence, classes have given me total control over the php output without even touching the html.

    If you look closely, I've even accounted for coloring each table row a different color, and coloring the table header black with white text.

    What more could you possibly want?

    The only true problem with this example is the text-alignment for a particular column of cells cannot be controlled without affecting the other columns as well.

    To account for this, I would simply assign a class to each <td> within a given column (e.g for the title columns class='title'). However, this method CAN get a little bloated if you go crazy assigning classes to every single element possible, so be careful. This makes it essential to collaborate with the designer as much as possible.

    All that being said, (and I'm sorry if all that was a bit elementary) as a developer, I always try to decide ahead of time which elements will need to be controlled in the design portion, and I apply css classes acordingly.
    Last edited by shoebox; Dec 23, 2002 at 04:57.

  23. #48
    SitePoint Zealot
    Join Date
    Oct 2002
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Starting with databases is generally a bad way to design an application. The more tables that you have in your application, the less usable your user interface will be.
    Isn't that a reason to START with databases?? To eliminate the quick solution of creating a NEW table each time you need to implement something new?


    For instance.. for a content driven website with all the standard stuff (articles, polls, comments, etc...) You can standardize the content of each of these types of 'publications' with the following scheme..

    Code:
    publication_types
      id (unique)
      type (varchar)
      count (int)
      timestamp (int)
    
    publications
      id (unique)
      type_id (int)
      title (varchar)
      leadin (text)
      keywords (text)
      count (int)
      views (int)
      comments (int)
      timestamp (int)
    The above two tables provide a way for me toaccount for the most common attributes that a published web item for this widget site will have.

    For an example, now that I have a 'publications' table.. Let's say I want to publish 'articles' on my website...

    I can now implement this in just a couple of steps...

    1.) Create a record in the publication_types table with the title 'Articles'

    2.) Create a table called 'articles' with fields that fit the needs for this type of publication.

    It would be a very simple table with only 3 fields that looks like this.
    Code:
    articles
      id (unique)
      publication_id (int)
      bodycopy (text)
    Here's another for an inventory (the item title would go in publications:title)
    Code:
    inventory
      id(unique)
      publication_id(int)
      item_price (decimal)
      item_stock (int)
    Another for polls (the poll question would go in publications:title)
    Code:
    poll
      id (unique)
      publication_id (int)
      answer (varchar)
      count (int)

    Note: that since views, comments, count, and timestamp are already handled in the publications table, there is no need to have it in the child table. This centralizes the key dynamic data and makes things very scalable.

    The idea with this is that I do not have to recreate a table with the same basic info.. I took care of it all with a parent table. This way I am consistant with my 'schemas' and updating the count and update timestamps is a breeze and uses the same method for all database driven content that I am publishing through my site.

    I dont think I would end up with somethign this efficient by starting with the user interface.

    P.S. Sorry for the long-winded, slightly off-topic post...
    Last edited by shoebox; Dec 23, 2002 at 04:42.

  24. #49
    SitePoint Member
    Join Date
    May 2004
    Location
    Phoenix, AZ
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, I would like to say that AwesomeTemplateEngine is well...awesome! However I'm having one small problem: how do I write a loop using ATE? I can manage to output one row of results, but that is all, so any help for this newby would be greatly appreciated.

  25. #50
    SitePoint Member
    Join Date
    Jan 2004
    Location
    NA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    interesting idea.

    i would love to play with it.


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
  •