Welcome Guest, Not a member yet? Register   Sign In
Best CodeIgniter Application Structure!
#1

[eluser]Clooth[/eluser]
Heya,

New poster (I think) here, just wondering what kind of custom application structures you guys have set up for your Ignited services.

I set up my application to work with the Doctrine ORM (doctrine-project.org), so I can easily build the database structures for each of my sites.

This is how mine works:

Code:
system/
sites/
- site1/
-- public/
-- system/
- site2/
-- public/
-- system/
- shared/
-- config/
-- helpers/
-- libraries/
-- models/
-- schema/

Each index.php in the site1/site2 folders includes lines like this:
Code:
$site_name = 'Webservice';
$site_description = 'Providing you services';

... snip ...

// Are we in development or production?
if (substr('INSERT_STAGE_HERE', -4) == 'HERE') {
  define('STAGE', 'development');
} else {
  define('STAGE', 'INSERT_STAGE_HERE');
}

... snip ...

$error_reporting = null;
switch (STAGE) {
  case 'production':
    $error_reporting = 0;
    $display_errors  = 'off';
    break;
  case 'development':
  case 'staging':
  default:
    $error_reporting = E_ALL & ~E_STRICT;
    $display_errors  = 'on';
    break;
}
error_reporting($error_reporting);
ini_set('Display_errors', $display_errors);

The reason there's a STAGE constant, is because the way I deploy my sites to the web goes through two stages before production, /development/ is when I deploy an unstable testing and playful build of the website, and /staging/ for publishing a build that has "ready" features but they are still in beta stage, so the last bits of testing are made in this stage.

Only from a /staging/ build do I deploy to production, to make sure things don't get ugly.

For deployment I use the ruby gem "Capistrano" (look it up on google), which makes it easy to fetch my site's source from bitbucket (awesome mercurial hosting) and move it to the appropriate folder in public_html.

There's also checks in the config/database.php for stage, so you can have separate databases for each type of build of your site.

I think this is a very powerful set up but I am still in the process of modifying it, probably adding support for shared public files (like images and javascript files), shared views and shared everything if you have a network of similar websites.

What kind of set up do you have?

Thanks,

Nico
#2

[eluser]n0xie[/eluser]
I think most of what you try to achieve can be done by your SCM, which would make it easier and less complex.

Take a look at this Git branching model
#3

[eluser]Clooth[/eluser]
I'm not trying to branch the release, I can do that with mercurial. What capistrano does is it runs scripts to replace variables within the source codes to prepare the application to be deployed live. It is not just dumping the source code repository to the server, it is setting the whole thing up and ready. Smile

I'm not trying to achieve anything, this is all programmed and running live already. Wink
#4

[eluser]n0xie[/eluser]
[quote author="Clooth" date="1287160029"]What capistrano does is it runs scripts to replace variables within the source codes to prepare the application to be deployed live. [/quote]
I know how Capistrano works. My point is, that if you have a different branch, you can have the differences in settings within the branch which means you don't have to run these scripts. You can just straight out deploy your branch. No fiddling with 'if environment is this than that' code.
#5

[eluser]Clooth[/eluser]
That's true, maybe I should branch them. Smile
#6

[eluser]ammonkc[/eluser]
[quote author="n0xie" date="1287170304"]
I know how Capistrano works. My point is, that if you have a different branch, you can have the differences in settings within the branch which means you don't have to run these scripts. You can just straight out deploy your branch. No fiddling with 'if environment is this than that' code.[/quote]
I've been trying to come up with a workflow for managing my different environments (development, staging, production) with branches within a git repo like this. But where I'm struggling to make this work correctly is when I need to merge changes from one branch into another. For example, I do all my development in the development branch. Then when the feature I've been working on is ready to be promoted to staging, I merge the development branch into the staging branch and push to the staging server. But at that point, I loose all of my environment specific configs. how can I promote a branch from development > staging while preserving staging configs? It's annoying to push some fresh updates from dev to staging then realize that your staging app is trying to connect to the dev database.
#7

[eluser]n0xie[/eluser]
[quote author="ammonkc" date="1297471621"]
But at that point, I loose all of my environment specific configs.[/quote]
Simple, don't put your config files inside your SCM.

This means that you have to set your config files for every new server you install it on, but you needed to do that anyway, so that doesn't change much.

If you have code that is environment specific, this might be a sign that you need to refactor.




Theme © iAndrew 2016 - Forum software by © MyBB