Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy How can I change a value on my html template from a class?

    This is my first attempt with OOP. I want to modify some values from a class, but I can't figure out how to do that from a different file. If I try to do that from where I have the class is working.

    So, all I want is basic html page where i can modify some values.

    HTML page

    Code:
        <!DOCTYPE html>
        <html>
        <body>
    
        <h1>My First Heading</h1>
    
        <p>My first paragraph.</p>
    
        </body>
        </html>
    My class.php

    PHP Code:
        <?php

        
    class show {

        public function 
    setTitle ($t) {
            
    $this->title $t;
                    }

        public function 
    seth1 ($h1) {
            
    $this->h1 $h1;
                    }

        public function 
    getTitle () {
            return 
    $this->title;
                    }
        public function 
    geth1 () {
            return 
    $this->h1;
                    }
        public function 
    render () {
                
    $s "<!DOCTYPE html>
        <html>
        <body>"
    ;
          
    $s .= "<title>";
        
    $s .= $this->title;
        
    $s .= "<title>";

          
    $s .= "<h1>";
        
    $s .= $this->h1;
        
    $s .= "</h1>";


        
    $s .= "<p>and so on</p>

            </body>
            </html>"
    ;
         }
         }
         
    ?>
    index.php

    PHP Code:
         <?php

         
    include dirname(__FILE__) . '/inc/class.php'// the above example

         
    $s = new show;
         
    $s->setTitle('title');
         
    $s->seth1('h1');
         
    $s->render();
         
    ?>
    This is just an example of what I'm trying to accomplish. All I get is a blank page...

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You don't appear to have any output in here. Perhaps the render() method is to either print or return the results of $s?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

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