canadabeeau Posted December 30, 2009 Share Posted December 30, 2009 I have a php function in functions.php function func_page_layout(){ $uri = $_GET['uri']; if($uri == ""){ $uri = "home"; } else { $uri = $uri; }; $mysqli = func_db_connect(); $qry = "SELECT * FROM `pages` WHERE `uri`='$uri' LIMIT 1"; $result = $mysqli->query($qry, MYSQLI_STORE_RESULT); $array = mysqli_fetch_array($result); $layout = $array['layout']; require_once('themes/default/layouts/layout001.php'); }; now this is not working but if in the page instead of executing the function I do the include straight out it works, any ideas? the PHP error code(s) Warning: require_once(themes/default/layouts/layout001.php) [function.require-once]: failed to open stream: No such file or directory in C:\inetpub\wwwroot\_inc\functions.php on line 148 Fatal error: require_once() [function.require]: Failed opening required 'themes/default/layouts/layout001.php' (include_path='c:\php\includes') in C:\inetpub\wwwroot\_inc\functions.php on line 148 Line #148 is require_once('themes/default/layouts/layout001.php'); Quote Link to comment https://forums.phpfreaks.com/topic/186644-require-error-in-a-function/ Share on other sites More sharing options...
mikesta707 Posted December 30, 2009 Share Posted December 30, 2009 the error is pretty clear. PHP couldn't find the file you specified. make sure the file is located where you expect it to be located, and your include path is correct Quote Link to comment https://forums.phpfreaks.com/topic/186644-require-error-in-a-function/#findComment-985764 Share on other sites More sharing options...
canadabeeau Posted December 30, 2009 Author Share Posted December 30, 2009 okay wwwroot/index.php (calls the function in functions.php) wwwroot/_inc/functions.php (require_once the layout file) wwwroot/themes/default/layouts/layout001.php Quote Link to comment https://forums.phpfreaks.com/topic/186644-require-error-in-a-function/#findComment-985765 Share on other sites More sharing options...
canadabeeau Posted December 30, 2009 Author Share Posted December 30, 2009 if I was th put the require_once straight in index.php all works well but as soon as it is placed in the function the errors appear. I have tried require_once('../themes/default/layouts/layout001.php'); Quote Link to comment https://forums.phpfreaks.com/topic/186644-require-error-in-a-function/#findComment-985772 Share on other sites More sharing options...
canadabeeau Posted December 30, 2009 Author Share Posted December 30, 2009 if I set it to use the URL path require_once('http://10.0.0.1/themes/default/layouts/layout001.php'); it works, any ideas guys?? Quote Link to comment https://forums.phpfreaks.com/topic/186644-require-error-in-a-function/#findComment-985780 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.