Welcome Guest, Not a member yet? Register   Sign In
Why the [system] directory?
#1

[eluser]Sundance[/eluser]
Hi all,

I am new to CI but a long time PHP developer. I develop web applications for distribution so others can run them on their server.

Up to now, whatever approach I took (all self made code, template engines, etc.) my distributions consists of a folder structure like this:

[appname]
- [includes]
- [js]
- [themes]
- [language]
-...

With CI unchanged a distribution would contain this:

[appname]
- [system]
---[application]
---[views]
---...

My question is: What is the system folder for? It seems to me as a useless folder level.

I am currently developing a test application with CI and I got rid of the system folder, moved the index.php in the [appname] folder and just changed:
Code:
$system_folder = "../appname";

That works pretty fine so far. However, since I am not to deep into all CI details, is there anything I am missing here? Is the system folder necessary for certain features?

Best regards,
Sundance
#2

[eluser]Adam Griffiths[/eluser]
The system folder contains CodeIgniter. The application folder contains all application specific data, config files, controllers et al. Without the system folder CodeIgniter won't work. It's much neater having two folders (system and application) than having many folders (libraries, helpers etc) and sub folders inside there for app specific and system files.

It's just the way CodeIgniter has been made, as simple as possible.

But if you mean why do we have a system folder for each application, then taking the system folder out of the web root, enabling access to it from many applications; well this is a good thing to do for your applications as it makes it easier to update CodeIgniter when a new release has been made.
#3

[eluser]Sundance[/eluser]
Hi Adam,

if it would be as you describe, then I would understand. But it is not. When I download CodeIgniter and unpack it, the following directory structure is created:
Code:
[codeigniter]
-[system]
  -[application]
  -[cache]
  -[codeigniter]
  -...
-[user_guide]
-index.php
-license.txt

As you can see, the application folder and all codeigniter folders are underneath the system folder. Only the user guide and the index.php is on the same level as [system].

My understanding is that all I need to distribute is the system folder. But then, why is the index.php file one level above that?

I hope this makes my question a little clearer.

Best regards,
Sundance
#4

[eluser]oddman[/eluser]
Sundance - I think more than anything it's about simplifying. If you have all your business logic within one folder (in this case: system), then anything outside of that is either:

- content or
- client-side logic and display (css, javascript.etc.)

In my view it's a great, organised way to split up the application.
#5

[eluser]xwero[/eluser]
Sundance did you move all the directories of the system directory to the application directory?
#6

[eluser]GSV Sleeper Service[/eluser]
first thing I do is change things around a bit, there's no need for any of the system files to live in the webroot. when a new version of CI is released I just update the system folder.
Code:
[system]
-[cache]
-[codeigniter]
-[database]
-....
[application]
-[config]
-[controllers]
-[helpers]
-...
[htdocs]
-[css]
-[images]
-index.php
#7

[eluser]Sundance[/eluser]
Thanks for your responses. I recon it is possible to change the folder structure around to meet your personal preferences. All you need to do is, change the url references accordingly in order to make the whole thing work.

The default CI distribution has everything under [system] (forget the user guide folder or now). Even the [application] folder is within [system]. I don't think that makes sense. I like the last suggestion:

Code:
[myapp]
index.pgp
-[system]
    -[cache]
    -[codeigniter]
    -[database]
    -[...]
-[application]
    -[config]
    -[controllers]
    -[errors]
    -[...]
Best regards,
Sundance
#8

[eluser]Dam1an[/eluser]
I have the same structure as Sundance, with the exception of moving the system directory up another level, so I can point multiple applications at it (and upgrade a single directory to upgrade all applications)
#9

[eluser]louis w[/eluser]
Personally I prefer the system directory inside the application one. Because of the fact that the system directory contains all of the base CI code, which shouldn't be changed, I like to get it out of the way. I also have added a directory inside application called assets which houses all my js, css and images. I keep these inside the application folder because I manage them with a asset manager self built library.
#10

[eluser]Daniel Moore[/eluser]
I generally, when hosting multiple sites on a shared server setup, will do something like the following:
Code:
[system]
[accounts]
--[client1name]
    --this_domain.php
    --[application]
    --[html]
       --index.php
--[client2name]
    --this_domain.php
    --[application]
    --[html]
       --index.php
I have a universal index.php that I do not have to change across accounts, because I can point to the same absolute system directory, and the application directory is always '../application'. I just do a "require_once('../this_domain.php');" at the beginning of the index.php. This also prevents me from having to touch config.php in "application/config" because I preset it to have the following:
$config['base_url'] = "http://".THIS_DOMAIN_NAME."/";

The constant THIS_DOMAIN_NAME is defined in the 'this_domain.php' file.

The advantage of this is I use an if-statement to check if I am running the app on my local development machine (XAMPP) or if it is on the live server. If on my local development machine, then it uses THIS_DOMAIN_ALIAS for the base_url. This way I don't have keep a separate configuration file for local and live, it just works.

this_domain.php includes the following:
Code:
if ($_SERVER['SERVER_NAME'] == 'host_I_defined_in_apache_config') // usually 'localhost'
{
  define('THIS_DOMAIN_NAME', 'host_I_defined_in_apache_config/example.com');
  define('MY_DB_USER', 'local_dbusername');
  define('MY_DB_PASSWORD', 'local_dbpassword');
  define('MY_DB_HOST', 'local_dbhostname');
  define('MY_DB_NAME', 'local_dbname');
}
else
{
  define('THIS_DOMAIN_NAME', 'www.example.com');
  define('MY_DB_USER', 'live_dbusername');
  define('MY_DB_PASSWORD', 'live_dbpassword');
  define('MY_DB_HOST', 'live_dbhostname');
  define('MY_DB_NAME', 'live_dbname');
}

As you can see, that also allows me to set up my database configuration so that I don't have to touch it either. That way, when I set up a new site, I just fill in the blanks (so to speak) in this one file and get started. It makes it much easier for me to migrate from local development machine to a live server, since I don't have to change settings back and forth.

It may not be the best practice, but I prefer to have only one version of all the files, and I don't want to maintain a separate copy for local development and live, even if it is just one or two files.




Theme © iAndrew 2016 - Forum software by © MyBB