Jump to content


Photo

How to render dynamic variable from a php file


  • Please log in to reply
5 replies to this topic

#1 sana

sana
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 October 2006 - 06:25 AM

hi there.

File A contains a class with set of variables and one of the variables is invoked from another file B.php. When we execute, A.php the output is $this->lang->login_user as opposed to displaying it's value. Could anyone help what I am missing?

File A:
*************
<?php
include './fglobal.php';

class junk extends ClassBase
{

	public $len;
	 function __construct()
	{
		$this->len=5;
	}
	function execute()
	{
		
		return $this->generate_pass($this->len);

	}
 	public $login_user="User";
	public $login_pass="password"	;
	public $submit ="submit";	
	
	public function displaypage()
	{
	
	$this->get_lang_file();
	$this->lang->login();
	//echo($this->file_open());
	//echo($this->lang->login_user);


$temp=$this->file_open();

echo ($temp);

	}

function file_open()  
{   

	$filename = "Flogin.php";

	if($fp = @fopen($filename, "r"))  
 	{   
	
           //$fp = @fopen($filename, "r");   
           $contents = fread($fp, filesize($filename));   
           fclose($fp);   
           return $contents;   
       }else{   
           return 'file not found';   
       }   
}  


}

$a =  new junk();
$a->displaypage();





//eval("echo(\$temp);");



?>

**************

File B
*************
$this->lang->login_user

*************



#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 28 October 2006 - 06:29 AM

Is this line ALL that is in B?

$this->lang->login_user


#3 sana

sana
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 October 2006 - 06:33 AM

Yes, file B contains just this line because I wanted to test it whether this will work or not. The idea is to keep all variables in a file and dynamically serve them to build a html file

#4 sana

sana
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 October 2006 - 06:38 AM

I am trying to build a login.php page and I want to keep the content template (the HMTL content with PHP variables referring to class). All I want is to read this login.php inside my main php file and execute it so that HMTL content is rendered as it is and the variables are executed at server side....

example of my login.php content template would like...

*************
<form action='{$this->self}?a=login&amp;s=on' method='post'>
<table>
  <tr>
    <td class='header' colspan='2'>{$this->lang->login_header}</td>
  </tr>
  <tr>
    <td class='tablelight' style='width:30%'>{$this->lang->login_user}</td>
    <td class='tablelight'>
      <input class='input' type='text' name='user' size='30' tabindex='1' />
    </td>
  </tr>
  <tr>
    <td class='tabledark'>
      {$this->lang->login_pass}<br />
      <a href='{$this->self}?a=login&amp;s=pass'>{$this->lang->login_forgot_pass}</a>
    </td>
    <td class='tabledark'>
      <input class='input' type='password' name='pass' size='30' tabindex='2' />
    </td>
  </tr>
  <tr>
    <td align='center' colspan='2' class='footer'>
      <input type='hidden' name='request_uri' value='' />
      <input type='submit' name='submit' value='submit' tabindex='3' />
    </td>
  </tr>
</table>
</form>
*******************

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 28 October 2006 - 06:50 AM

If that is the only line in the file then of course that is what is going to be outputed. Its not even within php tags. I suggest you look into a pre existing template engine as your second example demonstrates this is what you want to do.

There are plenty made in and for php.

#6 sana

sana
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 October 2006 - 06:55 AM

For some reason if the login.php content is stored in a database field, and when I read it and keep it in a variable and execute the content using eval() it works fine. But if I keep the content in a file and read it using fopen(), it does not render correctly. My question is, is there any encoding or something that I am missing?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users