doubledee — 2012-09-30T12:34:25-04:00 — #1
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?)
cpradio — 2012-09-30T12:40:24-04:00 — #2
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.
doubledee — 2012-09-30T13:08:00-04:00 — #3
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!
doubledee — 2012-09-30T13:22:06-04:00 — #4
BTW, what would be a better name for this than "URL"...
I am leaning towards $articleBaseURL
What do you think?
cpradio — 2012-09-30T13:28:00-04:00 — #5
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.
doubledee — 2012-09-30T13:37:49-04:00 — #6
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...
cpradio — 2012-09-30T16:30:40-04:00 — #7
Fair enough $articleBaseUrl works.