I have a "config" file where I define...
// Base URL (**Virtual Location)
define('BASE_URL', ENVIRONMENT === 'development'
I have been using this Constant with great success over the past year or so.
However, now I want to incorporate it into a Function that I am working on, and I'm not sure how its scope works?!
Here is my current Function...
$url = 'http://local.debbie/' . $section . '/articles/';
What do I need to do to replace that static URL with reference to my Constant so that when I switch between "Development" and "Production", everything still works"
Can my Constant - defined in my "config" file - be seen INSIDE my Function? (Or do I need to pass it into the Function? Or something else?)
You simply need to replace it with BASE_URL, so you end result would be something like
$url = BASE_URL . $section . '/articles/';
Constants have a global scope.
Thanks for the response.
Yeah, I sorta knew that, and my code - which looks like yours - seems to work, but I was still skeptical.
Now that I have "Jedi Approval", I'm good!
BTW, what would be a better name for this than "URL"...
I am leaning towards $articleBaseURL
What do you think?
Keep in mind, that variable only exists within your function, so $url is representative within the function. Outside of the function if assigning the value returned by genereateUrl to a variable, I'd use $articleUrl.
I meant like this...
// (e.g. "local.debbie/management/articles/" )
$articleBaseURL = generateArticleBaseURL($sectionSlug);
Outside of the function if assigning the value returned by genereateUrl to a variable, I'd use $articleUrl.
Doesn't "Article URL" make people think about something like this instead...
Fair enough $articleBaseUrl works.
This topic is now closed. New replies are no longer allowed.