tobimichigan Posted January 16, 2012 Share Posted January 16, 2012 Hi Guz, I'm stuck @ this code running a cms.. here are the directories: /.private # configuration directory /ww.incs # CMS function libraries /j # CMS JavaScript files /ww.php_classes # CMS PHP class files /ww.plugins # CMS plugins /ww.skins # templates Now the index is located outside of these..but anytime I try to launch it says: Warning: require(C:/xampp/htdocs/.private/config.php) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\Books\cms\packt\CMS Design Using PHP and jQuery_Code\2527OS_Code\2527_01_codesamples\chapter-01\cms\ww.incs\basics.php on line 26 Fatal error: require() [function.require]: Failed opening required 'C:/xampp/htdocs/.private/config.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\Books\cms\packt\CMS Design Using PHP and jQuery_Code\2527OS_Code\2527_01_codesamples\chapter-01\cms\ww.incs\basics.php on line 26 <?php session_start(); function __autoload($name) { require $name . '.php'; } function dbInit(){ if(isset($GLOBALS['db']))return $GLOBALS['db']; global $DBVARS; $db=new PDO('mysql:host='.$DBVARS['hostname'].';dbname='.$DBVARS['db_name'],$DBVARS['username'],$DBVARS['password']); $db->query('SET NAMES utf8'); $db->num_queries=0; $GLOBALS['db']=$db; return $db; } function dbQuery($query){ $db=dbInit(); $q=$db->query($query); $db->num_queries++; return $q; } function dbRow($query) { $q = dbQuery($query); return $q->fetch(PDO::FETCH_ASSOC); } define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/'); require SCRIPTBASE . '.private/config.php'; if(!defined('CONFIG_FILE'))define('CONFIG_FILE',SCRIPTBASE.'.private/config.php'); set_include_path(SCRIPTBASE.'ww.php_classes'.PATH_SEPARATOR.get_include_path()); now if you check line 26, its require SCRIPTBASE . '.private/config.php'; I tried resolcing the scriptbase directly to the location on xampp but its still giving same error any sugs? Link to comment https://forums.phpfreaks.com/topic/255108-function_require/ Share on other sites More sharing options...
tobimichigan Posted January 16, 2012 Author Share Posted January 16, 2012 sorry guz, my mistake. Could u folks believe that I've been battling with this code all night with a lot of distractions on the net. Only to discover my error as soon as I posted this. Here was my mistake: define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/'); require SCRIPTBASE . '.private/config.php'; if(!defined('CONFIG_FILE'))define('CONFIG_FILE',SCRIPTBASE.'.private/config.php'); set_include_path(SCRIPTBASE.'ww.php_classes'.PATH_SEPARATOR.get_include_path()); I defined <?php define('SCRIPTBASE', $_SERVER['DOCUMENT_ROOT'] . '/'); but this did not match my exact directory, hence the error. Its running now...but guz look its giving a new err on top of the "Hello World". output: Strict Standards: Non-static method Page::getInstanceBySpecial() should not be called statically in C:\xampp\htdocs\Books\cms\CMS Design Using PHP and jQuery_Code\2527OS_Code\2527_01_codesamples\chapter-01\cms\index.php on line 16 Hello World here's the index code: <?php // { common variables and functions include_once('ww.incs/common.php'); $page=isset($_REQUEST['page'])?$_REQUEST['page']:''; $id=isset($_REQUEST['id'])?(int)$_REQUEST['id']:0; // } // { get current page id if(!$id){ if($page){ // load by name $r=Page::getInstanceByName($page); if($r && isset($r->id))$id=$r->id; } if(!$id){ // else load by special $special=1; if(!$page){ $r=Page::getInstanceBySpecial($special); if($r && isset($r->id))$id=$r->id; } } } // } // { load page data if($id){ $PAGEDATA=(isset($r) && $r)?$r : Page::getInstance($id); } else{ echo '404 thing goes here'; exit; } // } echo $PAGEDATA->body; Here's line 16 <?php $r=Page::getInstanceBySpecial($special); whats the solution to line 16=> $r=Page::getInstanceBySpecial($special); ? Any ideas? Link to comment https://forums.phpfreaks.com/topic/255108-function_require/#findComment-1308053 Share on other sites More sharing options...
tobimichigan Posted January 16, 2012 Author Share Posted January 16, 2012 yea guz, sorry to have bothered u again... just saw my mistake: The methods are missing the static keyword. All I did was Change function getInstanceByName($name=''){ to public static function getInstanceByName($name=''){ in the /ww.php_classes # CMS PHP class files that contained the Page.php file <?php class Page{ static $instances = array(); static $instancesByName = array(); static $instancesBySpecial = array(); function __construct($v,$byField=0,$fromRow=0,$pvq=0){ # byField: 0=ID; 1=Name; 3=special if (!$byField && is_numeric($v)){ // by ID $r=$fromRow?$fromRow:($v?dbRow("select * from pages where id=$v limit 1"):array()); } else if ($byField == 1){ // by name $name=strtolower(str_replace('-','_',$v)); $fname='page_by_name_'.md5($name); $r=dbRow("select * from pages where name like '".addslashes($name)."' limit 1"); } else if ($byField == 3 && is_numeric($v)){ // by special $fname='page_by_special_'.$v; $r=dbRow("select * from pages where special&$v limit 1"); } else return false; if(!count($r || !is_array($r)))return false; if(!isset($r['id']))$r['id']=0; if(!isset($r['type']))$r['type']=0; if(!isset($r['special']))$r['special']=0; if(!isset($r['name']))$r['name']='NO NAME SUPPLIED'; foreach ($r as $k=>$v) $this->{$k}=$v; $this->urlname=$r['name']; $this->dbVals=$r; self::$instances[$this->id] =& $this; self::$instancesByName[preg_replace('/[^a-z0-9]/','-',strtolower($this->urlname))] =& $this; self::$instancesBySpecial[$this->special] =& $this; if(!$this->vars)$this->vars='{}'; $this->vars=json_decode($this->vars); } function getInstance($id=0,$fromRow=false,$pvq=false){ if (!is_numeric($id)) return false; if (!@array_key_exists($id,self::$instances)) self::$instances[$id]=new Page($id,0,$fromRow,$pvq); return self::$instances[$id]; } function getInstanceByName($name=''){ $name=strtolower($name); $nameIndex=preg_replace('#[^a-z0-9/]#','-',$name); if(@array_key_exists($nameIndex,self::$instancesByName))return self::$instancesByName[$nameIndex]; self::$instancesByName[$nameIndex]=new Page($name,1); return self::$instancesByName[$nameIndex]; } public static function getInstanceBySpecial($sp=0){ if (!is_numeric($sp)) return false; if (!@array_key_exists($sp,$instancesBySpecial)) $instancesBySpecial[$sp]=new Page($sp,3); return $instancesBySpecial[$sp]; } } thanks for reading..hope some1 learnt something... Link to comment https://forums.phpfreaks.com/topic/255108-function_require/#findComment-1308057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.