Jump to content

TheGreek

New Members
  • Posts

    7
  • Joined

  • Last visited

TheGreek's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @trq Thanks for your time I solved the issue. I was assuming that the Inculed file was linked to the index.php and then parsed but it is actually parsed in the instance of the class and the reult is linked to the index.php. Simply changing the <?php echo $page->name;?> in the index_h.php to <?php echo $this->name; ?> resolved the problem. Thanks
  2. use a relative path. pay attention to where the calling file is in relation to what is calling. for instance your css is in C://wamp/www/project name/css.css and your and your background image is at C://wamp/www/project name/images try #IDName {background-image:url(/images/imagename.jpg;} remember : Starting with "/" returns to the root directory and starts there Starting with "../" moves one directory backwards and starts there Starting with "../../" moves two directories backwards and starts there (and so on...) To move forward, just start with the first subdirectory and keep moving forward as seen in this article http://css-tricks.com/quick-reminder-about-file-paths/ the same should hold tru for included pathes
  3. being that $page is created before the call to include the header make it available to the header
  4. If the object is created in the included stdlib.php which is in the index.php i assume that the call to render which has the include for the header made on the same page would make the object available to the header. I see that I was wrong I just have no idea how to recode it. My main goal is to make the header and footer repond dynamically depending on what page is displayed. So i could dynamically set the title or relevent css or or even page specific content. I even tried <script src="/scripts/jquery.js"></script> <script> $(document).ready(function () { document.title = "Hello World!"; }); </script> written into the index_h.php but nothing. so i thought was maybe it had something to do with the fact that it was being included. i'm at a loss right now. any suggestions on making the header content and footer dynamic. thanks for your time
  5. do you have access to the database to verify the field width on the column
  6. Index.php <?php require 'php/stdlib.php'; $site->page->render(); foreach($page as $var => $value) { echo $var ." is ". $value." <br/>"; } ?> stdlib.php <?php //*************Site Initialization**********/// define("INC_DIR","inc/"); define("CSS_DIR","css/"); define("DEFAULT_HEAD",INC_DIR."index_h.php"); define("DEFAULT_FOOT",INC_DIR."index_f.php"); $currentPage=""; function __autoload($class) { include "classes/$class.php"; } function site_ini($site) { $siteprop = array( "siteName" => "Coredrilling Etc", "dbusername" => "root", "dbpassword" => "#######", "dbhostname" => "localhost", "defaultdbname" => "cce", "mtable" => "fed_tax_married", "stable" => "fed_tax_single" ); foreach($siteprop as $memb => $val ) { try{ $site->set($memb, $val); } catch(Exception $e){ { throw new Exception( 'Can Not set site Variable'.$memb, 0, $e); } } } } $site = new csite(); site_ini($site); $page = new cpage("welcome"); $site->setPage($page); ?> cpage.php <?php class cpage{ public $name; public $headers; public $footers; public $contents; private $writeback; public function get($property) { if (property_exists($this, $property)) { return $this->{$property}; } } public function set($property,$new_value) { if (!property_exists($this, $property)) { $this->{$property} = $new_value; } } public function __construct(){ $args = func_get_args(); if (func_num_args() == 1){ $this->name = $args[0]; $this->headers = DEFAULT_HEAD; $this->footers = DEFAULT_FOOT; } if(func_num_args() == 2){ $this->name = $args[0]; $this->pri_get_header($args[1]); $this->footers = DEFAULT_FOOT; } if (func_num_args()== 3){ $this->name = $args[0]; $this->pri_get_header($args[1]); $this->pri_get_footer($args[2]); } $this->pri_get_contents(); } public function render(){ include $this->headers; include $this->contents; include $this->footers; } public function get_headers(){ return $this->headers; } public function __toString() { return $this->name; } ////////PRIVATE FUNCTIONS private function pri_get_header($header){ $files = scandir(INC_DIR); foreach($files as $html_file) { if($html_file = $header){ $this->headers = INC_DIR . $html_file; } } } private function pri_get_footer($footer){ $files = scandir(INC_DIR); foreach($files as $html_file) { if($html_file = $footer){ $this->footers = HTML_DIR . $html_file; } } } private function pri_get_contents(){ $files = scandir(INC_DIR); foreach($files as $html_file) { if($html_file = $this->name.".php"){ $this->contents = INC_DIR . $html_file; } } } } ?> csite.php <?php class csite { public $page; public function _construct() { } public function get($property) { if (property_exists($this, $property)) { return $this->{$property}; } } public function set($property,$new_value) { if (!property_exists($this, $property)) { $this->{$property} = $new_value; } } public function setPage(cpage $page) { $this->page = $page; } public function render_page(){ $this->page->render(); } } ?>
  7. ok i have an index.php as so: <?php require 'php/stdlib.php'; $site->page->render(); foreach($page as $var => $value) { echo $var ." is ". $value." <br/>"; } ?> the obj creation for site and page is in the stdlib file and is obviously working cuz the -for each- loop prints out: name is welcome headers is inc/index_h.php footers is inc/index_f.php contents is inc/welcome.php It show that the object is created. I also did a var dump with proper results here is site---page---render: public function render_page(){ $this->page->render(); } here is page---render: public function render(){ include $this->headers; include $this->contents; include $this->footers; } however the result of the script is the following: Undefined variable: and also Trying to get property of non-object: both errors point to my $page object that i used in the include file for the page header: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title><?php echo $page->name; ?></title> <script src="/scripts/jquery.js"></script> </head> <body> The errors actually print out in the html title tag not on the screen meaning i have to use View Source on my browser to see it How do i get the $page object to be visible when using an include Im usually pretty good about finding answers myself but this thing has me stumped for two days now.(I have learned alot about many other things while searching for answer tho so I guess not all is lost) If anyone could help me I would greatly appreciate it. Probably should have added that the page and site object are instantiated in stdlib.php with the following $site = new csite(); site_ini($site); $page = new cpage("welcome"); $site->setPage($page);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.