Question

I am working on a small application with Laravel 4.1. I created an app/acme folder to contain most of my app specific code. I have a service provider named app/acme/AcmeServiceProvider.php where I am setting IoC bindings, Custom View templates and some Config variables.

My Custom Service Provider

...

View::addLocation(app('path').'/OneTimeNote/Views');

/* @TODO - Maybe a better place to put this would be in the app/config folder? */
Config::set('EXTERNAL_SITE_URL', 'http://www.example.com/#/');

/* @TODO - Probably could find a better spot for this, possibly in a lang folder? */
Config::set('EMAIL_SUBJECT', 'The note you created has been read and destroyed.');

...

I think having my custom View location in my service provider makes sense but what about the two entries below it?

The first Config is setting a value I can retrieve from my Controller so that I can build an external URL.

The second Config is setting a value I can use for an e-mail subject I'm sending the user. I thought about just hardcoding this value, but I wanted to put configurable text like this in one place for easy customization. I'd also like to utilize multiple languages in the future, so having some sort of 'lang' directory with different languages could be an answer I suppose?

My question: Is there a better place to put these two config statements rather than my Service Provider? Maybe they shouldn't be added to the Config at all but somewhere else? need advice.

Thanks!

Was it helpful?

Solution

Lets try by creating app/config/acme.php

and return array there e.g.

return array(

'EXTERNAL_SITE_URL' => 'SITE_URL',

'EMAIL_SUBJECT'     => 'SUBJECt_VALUE'

);

try to access like that config::get('acme.EXTERNAL_SITE_URL'). I hope it should work for you. Please share you experience ....

@Edited: I have tested that is working for me, so should be for you as well :)

@Edited: Language Part

You can add file in app/lang/en/acme.php (e.g. for english)

if there is another language you can add app/lang/it/acme.php (e.g. for italian)

return array(

"abc" => "This is text",

"def" => array(

      "sub1"    => "this is fist sub message",

      "sub2"    => "this is on sencond number",
    )

);

then you can get like App::setLocale('en');

echo Lang::get('acme.abc'); //output: This is text

echo Lang::get('acme.def.sub1'); //output: this is fist sub message

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top