SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I am trying to separate the php logic from the html presentation, and I need to echo an object's members in a table. What is the proper procedure, this:

    main.php:
    =============
    <?php
    include("Class_Object.php");
    $object = new Object($x, $y, $z);
    $object->multiply_members_by_two();

    ?>
    .....
    .....

    <td><?echo $object->member1; ?></td>
    =================================
    Or, should I put the object creation and function call in a separate file like "multiply_by_two.php" and do this:

    multiply_by_two.php:
    ==============
    <?php
    include("Class_Object.php");
    $object = new Object($x, $y, $z);
    $object->multiply_members_by_two();
    ?>
    =================

    main.php:
    ========
    <?php
    include("multiply_by_two.php");
    ?>
    ....
    ....
    <td><?echo $object->member1; ?></td>
    ================================
    With the latter method, the presentation file main.php is much cleaner, but I think the code is harder to follow because later on an object suddenly appears in a table, and it may not be clear where that came from.

  2. #2
    SitePoint Member
    Join Date
    May 2001
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the object creation code is not big and not
    scattered across a file a see no reason to put it to a separate file just for the sake of html purity , it's a case when
    you do purity only for the sake of it
    Alex
    Certified CodeCharge Developer
    Develop database-connected web sites
    without coding: http://www.codecharge.com
    ASP, ASP.NET, PHP, JSP, Perl, ColdFusion


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
  •