2

I like base_url() so much that I want to create another global function base_img_url() where I can define the url in the config.php file just like base_url(). How do I do this and where should the function be? Is this a common practice?

Right now I'm just defining a constant in constants.php.

3 Answers 3

3

Your are going right.

I am also doing the same, defining in constants.php file.

I do not think any other way, as you are expecting is possible. Defining in constants file, is the best and easiest plus non-problematic way.

What can be wrong doing like this ?

Sign up to request clarification or add additional context in comments.

1 Comment

To me, a constant makes sense.. unless for some strange reason the path is going to change mid-stream. The only difference is that you can pass arguments to a function, but having a function that just returns a static value seems pointless.
0

I don't see any point in doing this because you are just saving typing 1 or 2 words by it. None the less, you can create a helper function, make it return the path and add it to autoload. Then call it wherever you want.

Comments

0

Go to constants.php define('base_img_url', 'define constant path here');

and use likr that variable = base_img_url.'/path for concat';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.