Page 1 of 1

can't make text fit in..

Posted: Fri Dec 30, 2005 9:57 am
by IAD
Hey guys,

I'm working on an admin panel, and for the first time i wanted to use Templates.
I built a function that i'll replace the word "#pages" with it, and inside this function there's a switch().
When i'm replacing it, it won't show up instead of the "#pages" but will show up in the top of the page.

The class:

Code: Select all

<?Php

//-----------------------------------------------------------------
//	Author: Tal Gleichger
//-----------------------------------------------------------------
//	Company Name: IAD
//-----------------------------------------------------------------
//	Date Started: 9:43 PM 12/28/2005
//-----------------------------------------------------------------
//	Date Updated: _____Never_____
//-----------------------------------------------------------------

/*****************************************************************************
	All Rights Resered to IAD & GTM IL LTD 
	Any Code Copying is agains the law!
	Any Rights deletion is recoreded and will be repot!
*****************************************************************************/


	class adminTemplates{

				//----------------------------------------------
			// Actions: 
			//
			// 1) Getting HTML code
			// 2) Replacing HTML outputs
			// 3) Returning HTML only output
		//
		//----------------------------------------------

		private $tplfile; 
		private $navifile;
		private $rightsfile;
		private $doReplace;
		private $doOutput;
		public 	$template;
		public	$doGetLogo;
		public	$doGetNavi;
		public	$makeFopen_index;
		public	$makeFopen_navi;
		public	$makeFopen_rights;
		public	$getNavi;
		public	$getRights;


		public function getPages(){

			switch(@($_GET['a'])){

				case 'test':
					require "sources/admin/TPL/admin.css";
				break;

			}
			

		}

		public function createReplace($tplfile,$navi,$rights){
		
			//--
			// Opening the File and Getting Html inputs
			//--
	
			$this -> tplfile = $tplfile;
			$this -> navifile = $navi;
			$this -> rightsfile = $rights;
			
				$this -> makeFopen_index = fopen($this -> tplfile,'r+');
				$this -> makeFopen_navi = fopen($this -> navifile,'r+');
				$this -> makeFopen_rights = fopen($this -> rightsfile,'r+');

				$this -> template = fread($this -> makeFopen_index,filesize($tplfile));
				$this -> getNavi = fread($this -> makeFopen_navi,filesize($navi));
				$this -> getRights = fread($this -> makeFopen_rights,filesize($rights));

				//--
				// Replacing special chars and getting other file's instead
				//--	

				$this -> doGetLogo = str_replace('#logo','<img src="sources/admin/TPL/logo.jpg" alt="" />',$this -> template);
				$this -> doGetNavi = str_replace('#navi',$this -> getNavi,$this -> doGetLogo);
				$this -> doGetPages = str_replace('#pages',$this -> getPages(),$this -> doGetNavi);
				$this -> doGetRights = str_replace('#rights',$this -> getRights,$this -> doGetPages);

					$this -> doGetContents = $this -> doGetRights;

				//--
				// Finishing and returning the doGetContents
				//--
					
					return $this -> doGetContents;
		}

	}

?>
The function: getPages(); will return it contents in the top of the page, above the logo.


Marry christmas [did i wrote it correctly? :P] and happy hanukka, Tal.

Posted: Fri Dec 30, 2005 12:41 pm
by IAD
Anyone?

Posted: Fri Dec 30, 2005 12:48 pm
by Ambush Commander
I don't understand... what's your question?

Posted: Fri Dec 30, 2005 12:53 pm
by IAD
i'll explain:

You see the function getPages?

I want to replace the word "#pages" with it, i mean that in index.tpl, the word "#pages" will be replace with that function.

So what's the problem?

I got this TPL file:

Code: Select all

<table id="adminTable">
	<tr>
		<td class="logo" colspan="2">#logo</td>
	</tr>
	<tr>
		<td class="navi" valign="top">#navi</td>
		<td class="pages" valign="top">#pages</td>
	</tr>
	<tr>
		<td colspan="2">
			<div class="row1">
			#rights
			</span>
		</td>
	</tr>
</table>
See "#pages"? getPages(); will be there, and when i'm typing "?a=test" it won't print the admin.css in the <Td> but above the logo, above all the table.


Got it?

Posted: Fri Dec 30, 2005 12:58 pm
by josh
I'm assuming the get_pages method is getting it's contents from an output buffer? That is probably your issue

Posted: Fri Dec 30, 2005 1:04 pm
by IAD
not realy, getPages is a function that inside theres a switch costructor that will make the whol "?a
..."

and the problem that it shows the files above the table when it need to be in a colume (#pages).

Posted: Fri Dec 30, 2005 1:20 pm
by josh
ah, I wasn't even paying attention to your code... well what you need to do is have your function return the contents of that file, rather then output them, we do that with a buffer which means it takes all of the output and stores it somewhere where we can get to it and then decide what to do, in this case we simply start the buffer, output the contents of admin.css, then the ob_get_clean() function returns the buffer, then turns off the output buffering

Code: Select all

public function getPages(){
	ob_start();
	switch(@($_GET['a'])){
		case 'test':	require "sources/admin/TPL/admin.css";	break;
		default:	echo 'Invalid request'; break;
	}
	return(ob_get_clean());
}

Posted: Fri Dec 30, 2005 1:25 pm
by IAD
Ohhh man you're the best!

Thanks man!