Page 1 of 1

[SOLVED] Unexpected results with class

Posted: Mon Jul 12, 2004 11:50 am
by Chonk
Ive been playing around with something to keep be busy and have ran into a problem.
It seems within the submenu it prints $contents, i have no idea why or how but it does. $url somehow keeps getting filled with $contents . I basically do some quick checking to see what page im on to show relevent links . When i set the content like:

Code: Select all

$page = new layout();
$page->setcontent('test');
nothing is shown and the link system works.

Here is my (ugly ?) code which is a class i use for layouts:

Code: Select all

<?
 class layout
{
   
   var $content;
   var $url;
   
   function layout()
  {
    $this->setpage();
    $this->startsess();
   } 
  
   function setcontent($newcontent)
  {
    $this -> $content = $newcontent;
  }
 
    
   function setpage()
  {
    $cut_page = explode("/",$_SERVER['SCRIPT_NAME']);
     $this -> $url = $cut_page[2];  
  }
 
   function banner()
  {
  
    echo "<html> \n<body> \n";
    echo"<table width=100% height=100% border=0 cellpadding=0 cellspacing=1 bgcolor=000000 > \n";
    echo "<tr bgcolor=#efefea height=10% width=100%> \n";
    echo "<td><center>Logo Banner thingy</center>  \n";
    echo "</td></tr> \n";
    echo "<tr bgcolor=#efefeg height=5% > \n";
    echo "<td>  \n";
    $this -> submenu();
    echo "</td> \n";
    echo "</tr>  \n";
    echo " <tr height=70% width=100% bgcolor=#efefea><td colspan=2>  \n";
  } 
  
   function menu()
  {
   echo "<table width=100% height=100% border=0 cellspacing=0 cellpadding=0 rules=cols >  \n";
   echo "<tr >  \n";
   echo "<td align=left height=100% width=10% bgcolor=efefeg valign=top >  \n";
   echo "<center ><u>.:Menu:.</u></center>  \n";
   $this -> links();
   echo "</td>  \n";
  } 
  
   function main()
  {
   echo "<td width=90% valign=top>  \n";
   echo $this -> $url ;
   echo "</td></tr></table> \n";
   echo "</td></tr></table> \n";
   echo "</body> \n</html> \n";
  
  } 
  
   function styles()
  {
   echo "<style> \n";
   echo "p {color:black; font-size:13pt} \n";
   echo ".main {color:black; font-size:13pt; }\n";
   echo "a:link,a:visited,a:active {color:black; font-size:10pt}  \n";
   echo ".submenu {color:black; font-size:13pt; text-align:right}  \n";
   echo "</style>  \n";
  } 
  
   function links()
  {
   echo "<a href=register.php >Register</a>  \n";
   echo "<a href=stats.php >Stats </a>  \n";
   echo "<a href=contact.php >Contact</a>  \n";
  }
 
   function submenu()
  {
   echo $this->$url;

    switch($this->$url)
   {
      case 'index.php':
    
        $this->sessregd();
        echo "</p>";
        break;
          
      case 'stats.php':
      
           echo "<p class=submenu><a href=stats.php?page=add>Add stats</a>
                 <a href=stats.php?page=view>View stats</a>";
           $this->sessregd();
           break;
   }
   
  }  
 
   function sessregd()
  {
    if( session_is_registered('logged_in'))
   {
    echo "<a href=killsess();>Logout</a></p>";
   }
    else
   { 
    echo "<p class=submenu><a href=login.php>Login</a> ";  
   }
  }  
 
   function startsess()
  {
   session_start();
  }
 
   function setlogin($uname)
  {
   $_SESSION['logged_in'] = $uname;
  } 

   function killsess()
  {
   session_destroy();
  }  

   function show()
  {
   $this->styles();
   $this->banner();
   $this->menu();
   $this->main();
  } 

}
?>
Any comments would also be great.

feyd | made the topic subject a bit more useful

Posted: Mon Jul 12, 2004 11:55 am
by feyd
the following have errors..

Code: Select all

function setcontent($newcontent) 
  { 
    $this -> $content = $newcontent; 
  } 

    
   function setpage() 
  { 
    $cut_page = explode("/",$_SERVER['SCRIPT_NAME']); 
     $this -> $url = $cut_page[2];  
  } 

  function main() 
  { 
   echo "<td width=90% valign=top>  \n"; 
   echo $this -> $url ; 
   echo "</td></tr></table> \n"; 
   echo "</td></tr></table> \n"; 
   echo "</body> \n</html> \n"; 
  
  } 


   function submenu() 
  { 
   echo $this->$url; 

    switch($this->$url) 
   { 
      case 'index.php': 
    
        $this->sessregd(); 
        echo "</p>"; 
        break; 
          
      case 'stats.php': 
      
           echo "<p class=submenu><a href=stats.php?page=add>Add stats</a> 
                 <a href=stats.php?page=view>View stats</a>"; 
           $this->sessregd(); 
           break; 
   } 
    
  }
$this->$content and $this->$url should be $this->content and $this->url respectively.

Posted: Tue Jul 13, 2004 10:07 am
by Chonk
I dont know how i didnt spot it or why i could reference $content by $url and get the same results.
Works fine now thou, thank you.
Oh sorry about the topic name aswell.