ricky spires Posted September 24, 2011 Share Posted September 24, 2011 hello. I have some oop code that pulls information about a page out of a mysql db but i dont want to put the code on every page. Instead in want to put it in the a function and pass it back to each page. do i put it in a function in my functions.php file or can i put it into my includes/pages.php includes file ?? the code looks for the page name on the page and then pulls that pages info from the db. this code works on the page - home.php <?PHP require_once("../includes/initialize.php"); $currentPages = Pages::find_all(); $pName = "adminHome"; $page_id = ""; $visible = ""; $pageZones = ""; $pageCRUD = ""; $pageTypes = ""; $module = ""; $title = ""; $sub_title = ""; $description = ""; $image = ""; $about = ""; foreach($currentPages as $currentPage){ $page_id = $currentPage->id; $pageName = $currentPage->pageName; $visible = $currentPage->visible; $pageZone = $currentPage->pageZones_id; $pageCRUD = $currentPage->pageCRUD_id; $pageType = $currentPage->pageTypes_id; $module = $currentPage->module_id; $title = $currentPage->title; $sub_title = $currentPage->sub_title; $description = $currentPage->description; $image = $currentPage->image; $about = $currentPage->about; if($pageName == $pName){ echo $pageName.'<br/>'; echo $page_id.'<br/>'; echo $visible.'<br/>'; echo $pageZone.'<br/>'; echo $pageCRUD.'<br/>'; echo $pageType.'<br/>'; echo $module.'<br/>'; echo $title.'<br/>'; echo $sub_title.'<br/>'; echo $description.'<br/>'; echo $image.'<br/>'; echo $about.'<br/>'; } } ?> i would like to be able to just put global $page or something like that to get all the db info for each page. i tried this in my includes/pages.php includes file but it cant get the page name. public static function find_by_pageName(){ global $database; global $pName; $sql = "SELECT * FROM ".self::$table_name." WHERE pageName=".$pName.""; $result_array = self::find_by_sql($sql); return !empty($result_array) ? array_shift($result_array) : false; } any suggestions ???? whats the best way to do this ? thanks ricky Quote Link to comment https://forums.phpfreaks.com/topic/247805-can-i-put-my-code-into-a-single-global-in-oop/ Share on other sites More sharing options...
trq Posted September 24, 2011 Share Posted September 24, 2011 I have some oop code No you don't. Quote Link to comment https://forums.phpfreaks.com/topic/247805-can-i-put-my-code-into-a-single-global-in-oop/#findComment-1272489 Share on other sites More sharing options...
ricky spires Posted September 25, 2011 Author Share Posted September 25, 2011 ok, so im new to this oop stuff. how would i make it oop then ? Quote Link to comment https://forums.phpfreaks.com/topic/247805-can-i-put-my-code-into-a-single-global-in-oop/#findComment-1272531 Share on other sites More sharing options...
KevinM1 Posted September 25, 2011 Share Posted September 25, 2011 ok, so im new to this oop stuff. how would i make it oop then ? OOP is a topic far too broad to adequately address in a forum post. Suffice it to say, OOP isn't about using objects as mere function collections. If you really want to learn OOP in PHP, get the book PHP 5 Objects, Patterns, and Practice by Matt Zandstra. It's the best introduction to OOP available. Quote Link to comment https://forums.phpfreaks.com/topic/247805-can-i-put-my-code-into-a-single-global-in-oop/#findComment-1272534 Share on other sites More sharing options...
ricky spires Posted September 25, 2011 Author Share Posted September 25, 2011 thanks Quote Link to comment https://forums.phpfreaks.com/topic/247805-can-i-put-my-code-into-a-single-global-in-oop/#findComment-1272538 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.