oop matter
Posted: Tue Nov 17, 2009 5:52 am
I wonder if there is nayone there, could help me with this issue, I have class called pages that suppose to query the abstract data layer and get the result as an array and then the class transform this result into json.
I created a testing class to instantiate this class and print the result. However I managed to print json form ($json_res;) from within the class but not from the testing.php, I don't understand this behave?!!
----------------------------------------------------------------------------
<?php
include '/Database.php';
class page{
private $page_id; // page_id
private $title;
private $discription;
public $res; // the result Array from DAL
public $json_res; // JSON transform from $res
// Constractors
function __construct($page_id)
{
//setters
$this->setPageId($page_id);
//getters
//$this->getPage($page_id);
}
// Setter Functions
public function setPageId($Inpage_id)
{
$this->setPageId = $Inpage_id;
}
// Getter Functions
public function getPage($page_id)
{
$db = new crud();
$db->connect();
$db->select('pages', '*' , 'page_id ='.$page_id);
$res = $db->getResult();
$json_res = JSON_encode($res);
echo $json_res; // this works fine?!!!
return $json_res;
}
}//End of page class
?>
--------------------------------------------------------------------------------
<?php
function __autoload($class) {
require_once("classes/$class.class.php");
}
$page_id=$_GET["q"]; // Create object of class page and assign the query that's been passed by Ajax call
$p = new page($page_id); // creating an object
echo $p->json_res; ///////this doesn't work at all ?!!!!!
?>
---------------------------------------------------------------------------------
I created a testing class to instantiate this class and print the result. However I managed to print json form ($json_res;) from within the class but not from the testing.php, I don't understand this behave?!!
----------------------------------------------------------------------------
<?php
include '/Database.php';
class page{
private $page_id; // page_id
private $title;
private $discription;
public $res; // the result Array from DAL
public $json_res; // JSON transform from $res
// Constractors
function __construct($page_id)
{
//setters
$this->setPageId($page_id);
//getters
//$this->getPage($page_id);
}
// Setter Functions
public function setPageId($Inpage_id)
{
$this->setPageId = $Inpage_id;
}
// Getter Functions
public function getPage($page_id)
{
$db = new crud();
$db->connect();
$db->select('pages', '*' , 'page_id ='.$page_id);
$res = $db->getResult();
$json_res = JSON_encode($res);
echo $json_res; // this works fine?!!!
return $json_res;
}
}//End of page class
?>
--------------------------------------------------------------------------------
<?php
function __autoload($class) {
require_once("classes/$class.class.php");
}
$page_id=$_GET["q"]; // Create object of class page and assign the query that's been passed by Ajax call
$p = new page($page_id); // creating an object
echo $p->json_res; ///////this doesn't work at all ?!!!!!
?>
---------------------------------------------------------------------------------