views:

17

answers:

1

I need to load controllers and models from a different folder than the default one. I am using a Linux system.

I am building a simple CI application for some people, for use on a shared hosting I own. But I want to give them access only to /views folder and some /config files. And this is why I need to store the controllers and models in a different folder on the same level as /public_html folder or maybe somewhere in the linux system.

I consider this would be a better solution than encoding files

A: 

CodeIgniter permits you to organize your controllers,views and config files into sub-folders. As far as I know it doesn't permit it for models (at least documentation doesn't mention it, I've not tried myself).

As your are in a Linux system, you can create a symbolic link to reference to another directory in the filesystem.

So you can create the directories:

application/config/public
application/controllers/public
application/views/public

And then create in your /public_html symbolic links ponting to these directories:

/public_html/config -> application/config/public
/public_html/controllers -> application/controllers/public
/public_html/views ->application/views/public

When your customers upload files to /public_html/config, they will be also available in application/config/public. The same applies for /public_html/controllers and /public_html/views.

The command syntaxis to creates symlinks is

# ln -s target name

i.e:

# ln -s application/config/public /public_html/config

If you don't have console access to your hosting you can create the links using the PHP function symlink() .

To load a view/config/controller from a subfolder you only have tu prepend the directory name in the $this->load->...() function call. i.e:

$this->load->view('public/my_view);

Check CI documentation for more info about organizing your files into sub-folders.

Stolz
Thank you very much. I was thinking to symbolic links, I know about ln, but could be a bit risky. anyway, have a look here: http://codeigniter.com/forums/viewthread/158193/and yes, my method works for libs and models. just checked. tomorrow I'll check yours. thanks.
Ady Mareshal