{CCM:BASE_URL} not working in php development
Permalink
Hi there, I am building a new site and it is not yet set to the domain. I am building it on the server IP:
http://123.456.789.0/myNewSite
I am writing loads of php which include links and I have always inserted the FULL URL +index.php (http://123.456.789.0/myNewSite/index.php) whilst developing because {CCM:BASE_URL} does not seem to work in php (it only works in html). When the URL is applied post dev, I have to go back and change all the links which is tedious and I worry about missing something...
There must be a better way for me to deal with this. I have tried defining the 'base_url' & 'dir_rel' in site.php but to no avail.
Any pointers would be gratefully received
Thanks
Rob
http://123.456.789.0/myNewSite
I am writing loads of php which include links and I have always inserted the FULL URL +index.php (http://123.456.789.0/myNewSite/index.php) whilst developing because {CCM:BASE_URL} does not seem to work in php (it only works in html). When the URL is applied post dev, I have to go back and change all the links which is tedious and I worry about missing something...
There must be a better way for me to deal with this. I have tried defining the 'base_url' & 'dir_rel' in site.php but to no avail.
Any pointers would be gratefully received
Thanks
Rob
Hi rc255,
What version of concrete5 are you using?
If you are using version 5.7, there are many useful path constants that can be used for building URLs.
Examples:
The BASE_URL constant is the URL of the concrete5 install directory
The DIR_REL constant is the relative URL of the concrete5 install directory
Another option is URL:to().
- resolves a URL from data
- accepts comma separated values
- can resolve a URL based on a page object
- it raw URL encodes (rawurlencode()) non-alphanumeric characters and whitespace in strings (for example, white space is replaced with %20)
- it adds forward slashes between segments
- it does not trim() strings
Examples:
What version of concrete5 are you using?
If you are using version 5.7, there are many useful path constants that can be used for building URLs.
Examples:
The BASE_URL constant is the URL of the concrete5 install directory
echo BASE_URL; // output: //http://localhost/concrete5
The DIR_REL constant is the relative URL of the concrete5 install directory
echo DIR_REL; // output: // /concrete5
Another option is URL:to().
- resolves a URL from data
- accepts comma separated values
- can resolve a URL based on a page object
- it raw URL encodes (rawurlencode()) non-alphanumeric characters and whitespace in strings (for example, white space is replaced with %20)
- it adds forward slashes between segments
- it does not trim() strings
Examples:
echo URL::to('/dashboard/system/basics/social'); // output: //http://localhost/concrete5/index.php/dashboard/system/basics/social...
$page_object = Page::getByID(304); echo URL::to($page_object); // output: //http://localhost/concrete5/index.php/scratch-pad... // - the page that has the ID of 304 is retrieved as a page object // - URL:to() uses this page object to get the URL
Brilliant! Thanks very much mate :)
This website is a new site for an existing URL on a different server, therefore it is developed on the new IP/directory prior to switchover...
I hope this makes sense