Welcome Guest, Not a member yet? Register   Sign In
shold I move this code in my .config file??
#1

[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
#2

[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.
#3

[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
#4

[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! (-:
#5

[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
#6

[eluser]Aken[/eluser]
http://ellislab.com/codeigniter/user-gui...onfig.html




Theme © iAndrew 2016 - Forum software by © MyBB