Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
"Template" cl***: Simple question
Old
  (#1)
Micky Hulse
Guest
 
Posts: n/a
Default "Template" cl***: Simple question - 05-14-2007, 04:21 AM

Hello,

I have a couple cl***es that generate navigation and a few other dynamic
xHTML template-based things...

What is standard practice for calling your template cl***es? In other
words: Is it good practice to create the cl*** object for every page
view, or is there a better way to cache the object? I am using PHP 4.x.

Any good tips and/or tutorials out there that cover this type of thing?
Basically I am trying to get away from using includes and/or simple
function calls.

Sorry if silly question... I am kinda new to cl***es and how best to use
them.

TIA!
Cheers,
Micky

--
Wishlists: <http://snipurl.com/1gqpj>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: [PHP] "Template" cl***: Simple question
Old
  (#2)
Micky Hulse
Guest
 
Posts: n/a
Default Re: [PHP] "Template" cl***: Simple question - 05-14-2007, 04:21 AM

Micky Hulse wrote:
> What is standard practice for calling your template cl***es? In other
> words: Is it good practice to create the cl*** object for every page
> view, or is there a better way to cache the object? I am using PHP 4.x.


Ack! Just found this great thread on Sitepoint:

<http://www.sitepoint.com/forums/showthread.php?t=468429>

Hehe, I wrote my email to the PHP list before checking my Sitepoint xml
feed.

Seems like the above thread has given me my answer.

Thanks all!
Sorry to bug the list.
Cheers,
Micky


--
Wishlists: <http://snipurl.com/1gqpj>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
OOB problem, super stumped.
Old
  (#3)
Brian Seymour
Guest
 
Posts: n/a
Default OOB problem, super stumped. - 06-02-2007, 08:55 PM

I am super stumped. This works fine separately but when I put everything
together it breaks. I has an authenticate cl*** and a sql cl***. However I
always get the same error.



SQL cl***.

<?php



cl*** SQL {

public $host;

public $user;

public $p***;

public $conx;

public $db;

public $dbname;

public $query;

public $result;

public $fetchedArray;

public $nRows;



public function __construct($host,$user,$p***,$dbname = null){

$this->host=$host;

$this->user=$user;

$this->p***=$p***;

$this->conx=$this->connection($host,$user,$p***);

if (!is_null($dbname)){ $this->selectDb($dbname); }

}



final public function connection($host,$user,$p***){

$this->conx=mysql_connect($host,$user,$p***) or
die(mysql_error());

}



final public function selectDb($db){

$this->db=mysql_select_db($db);

}



final public function query($query){

$this->result=mysql_query($query, $this->conx);

echo mysql_error();

echo $query;

return $this->result;

}



final public function fetchArray($query){

$this->result=$this->query($query);


$this->fetchedArray=mysql_fetch_array($this->result,MYSQL_***OC);

return $this->fetchedArray;

}



final public function makeArray($query){

$this->curArray=mysql_fetch_array($query,MYSQL_***OC);

return $this->curArray;

}



final public function numRows($result)

{

$this->nRows=mysql_num_rows($result);

return $this->nRows;

}



public function __destruct(){

if (isset($this->connection)){
mysql_close($this->connection); }

}

}

?>



Authenticate cl***



<?php



cl*** Authentication extends SQL {

public $errorMsg;



public function __construct(){echo "Auth constructed";}



final public function verifyCreds ($user, $p***, $table)

{

$result = $this->query("SELECT * FROM $table where
$user='$p***'");



if ($this->numRows($this->result) == 0)

{

$this->errorMsg = "Incorrect Username/P***word
Combo";

return false;

}

else

{

// debugging lines \/

echo "login good!";

// debugging lines /\

return true;

}



}



public function __destruct(){}

}

?>



Normal page.

<?php





/************************************************** **********

* common.php

*

* project: Renegades Revenge

* programmer: Brian Seymour

************************************************** **********/



// autoload cl***es

function __autoload($cl***_name) {

require_once 'includes/cl***es/cl***_' . strtolower($cl***_name)
.. '.php';

}



// initialize Renegades Revenge database

$database = new SQL($host,$user,$p***,"aerocor_renegade");



// login

if (isset($_GET['login']))

{

$auth = new
Authentication($host,$user,$p***,"aerocor_renegade ");

if
($auth->verifyCreds($_POST['username'],$_POST['p***word'],"players"))

{

echo "logged in good!";

}

}



?>



The form is just 2 fields. Username and p***word. I get this error.



Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource
in /home/aerocor/public_html/rr/includes/cl***es/cl***_sql.php on line 52
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /home/aerocor/public_html/rr/includes/cl***es/cl***_sql.php on
line 71



I put some simple query and display code in the constructor for the SQL
cl*** and it outputted from the database with no problem, that's whats
weird.



Any help would be great, thanks.



Brian


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top