Welcome Guest, Not a member yet? Register   Sign In
problem with require_once inside a view
#1

I have a require_once 'inc/functions.php'; in a view and it works fine.
I would like to move functions.php to the same folder that the css files are in.
This css files are accessed like this: href=$baseurl.'inc/newmenu.css'
However I cannot access functions.php like that (require_once $baseurl.'inc/functions.php'; ) and get the error:
Failed opening required 'http://localhost:8030/inc/functions.php'
So, how might I access it then?
Reply
#2

require and require_once are generally for paths, not URLs. Your use of $baseurl would seem to indicate that you are trying to load a URL. Instead, try to use constants like FCPATH, which is the path to the "Front Controller" or index.php. Like this:

FCPATH . 'inc/functions.php'
Reply
#3

(02-24-2016, 12:04 AM)skunkbad Wrote: require and require_once are generally for paths, not URLs. Your use of $baseurl would seem to indicate that you are trying to load a URL. Instead, try to use constants like FCPATH, which is the path to the "Front Controller" or index.php. Like this:

FCPATH . 'inc/functions.php'

Excellent! Never heard of FCPATH before but it works great. Thanks.
Reply
#4

(02-24-2016, 10:45 AM)cupboy Wrote:
(02-24-2016, 12:04 AM)skunkbad Wrote: require and require_once are generally for paths, not URLs. Your use of $baseurl would seem to indicate that you are trying to load a URL. Instead, try to use constants like FCPATH, which is the path to the "Front Controller" or index.php. Like this:

FCPATH . 'inc/functions.php'

Excellent! Never heard of FCPATH before but it works great. Thanks.

Glad to see that you've learned something new in FCPATH, but there are two more important things to note here:

- Having scripts such as your functions.inc.php in a publicly-accessible area is a bad idea in the first place.
- require_once() (and its similar counterparts) load local filepaths, not URLs.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB