I'm working on calling scripts from the database if they match a function that's included. Right here is what I'm using now: 3 Functions to Call Page Content:
public function ViewPageDetails() {
global $db;
$query = <<<SQL
SELECT title,body
FROM inv_pages
WHERE id = :getid
SQL;
$resource = $db->db->prepare( $query );
$resource->execute( array (
':getid' => $_GET['id'],
));
foreach($resource as $row){
$this->title = $row['title'];
$this->body = $row['body'];
}
}
public function ViewPageTitle() {
self::ViewPageDetails();
return $this->title;
}
public function ViewPageBody() {
self::ViewPageDetails();
if( is_callable($this->body) )
$this->body();
else {
echo $this->body;
}
}
I thought that that would work to call the function, but instead throws the error:
Fatal error: Call to undefined method pages::body()
Now a function I do have that would work on the flip side is
public function testcall() {
global $db;
$query = <<<SQL
SELECT body
FROM inv_pages
WHERE id = :getid
SQL;
$resource = $db->db->prepare( $query );
$resource->execute( array (
':getid' => $_GET['id'],
));
foreach($resource as $row){
if( is_callable($row['body']) )
$row['body']();
else {
echo $row['body'];
}
}
}
So $this->body()
is an illegal method, but $row['body']()
is perfectly fine to call. If anyone knows a way to use $this->body()
instead of $row['body']()
any input would be appreciated. If you need clarification please ask. I think I put the issue in pretty well however.