CodeIgniter Forums
shold I move this code in my .config file?? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: shold I move this code in my .config file?? (/thread-49453.html)



shold I move this code in my .config file?? - El Forum - 02-20-2012

[eluser]zoreli[/eluser]
Hi
I am fairly new with CI, and I have a question.

I have the following code in my controller at this time:

Code:
$config['upload_path'] = '/Library/WebServer/Documents/ciAdmin/backOffice/backOfficeImages/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048';
$config['max_width']  = '1024';
$config['max_height']  = '768';

The code works, and I have no problem with it whatsoever. However, I read that is good practice to have skinny controllers, so therefore my question.

I think that I should move this code in config file, but how I should access it from my controller later? Also, I might have more config variables for videos for example or pdf files.

How should I name my variables to avoid confusing? Can I use other name instead of $config?
For example can I use the name $configImage here instead of config in the above example?

Regards, Zoreli


shold I move this code in my .config file?? - El Forum - 02-20-2012

[eluser]Aken[/eluser]
Specific configuration options for libraries can be in the controllers no problem. That's not against any unwritten MVC rule.

You might want to create a separate config if you find yourself using the same config options over and over - then you don't have to keep repeating your code.


shold I move this code in my .config file?? - El Forum - 02-21-2012

[eluser]zoreli[/eluser]
Hi Aken

Thanks for your response. If I make my config file, where should I save that file? And how can I access my variables after? Can you post some example of the code?

Regards, Zoreli


shold I move this code in my .config file?? - El Forum - 02-21-2012

[eluser]Mauricio de Abreu Antunes[/eluser]
Hey,

I use my own lib for image upload.
My config for upload is in "config/upload.php". IMHO it is the best way to structure your config file. Smile

In your controller, use
Code:
$this->load->config('upload');

Bye! (-:


shold I move this code in my .config file?? - El Forum - 02-21-2012

[eluser]Rolly1971[/eluser]
when making a config file you put it into: application/config folder. Easiest way to access it after that is to autoload it. just add the file name without the .php extention to the autload['config'] array in application/config/autoload.php


shold I move this code in my .config file?? - El Forum - 02-21-2012

[eluser]Aken[/eluser]
http://ellislab.com/codeigniter/user-guide/libraries/config.html