• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Help/Suggestion] New project - Backend and Frontend Setup

#1
[eluser]Glazz[/eluser]
Hey there, i'm starting another project using CI.. this time i want to have only one application but i want to have an admin area also.

In my other projects i have 2 application folders ( 2 different index.php files ) 1 system folder

Something like:
Quote:admin
| protected ( this haves all the CI application stuff )
| config
| controllers
| ....
| index.php
site
| protected ( this haves all the CI application stuff )
| config
| controllers
| ....
| index.php
system


And it works like i wanted, but the downside is, i have duplicated code, need to setup two applications ( database and config settings ), and it is a pain in the a** for my clients to understand if they need to change something...

----

Now i want to try to build this new project using only one application.

I have:
- CodeIgniter 2.1.0
- Modular extensions HMVC by wiredesignz

And the work i have done so far is:

I have two extended CI_Controllers
Quote: | MY_Controller extends CI_Controller
| MY_Admin extends MY_Controller

One for Frontend and other for Backend ( admin )

In my modules directory i have:
Quote:modules
| admin
| clients
| controllers
| admin.php ( this extends the backend controller )
| models
| views


I have setup the routes like this:
Code:
$route['admin/([a-zA-Z0-9_-]+)/(:any)']     = '$1/admin/$2';
$route['admin/([a-zA-Z0-9_-]+)']   = '$1/admin/index';


So this way i can access http://localhost/admin/$my_controller[/$my_method]


In my backend controller i'm going to check if the user haves permissions and that good stuff...


Do you guys think this is a good setup ?

And there is some way that i have all the admin modules in one folder ? And the frontend in another folder ?

#2
[eluser]Glazz[/eluser]
Well i came up with a "solution" not the best one but it is working so far...

For now i can have both config.php and database.php elsewhere.

My edits is:
application/config/config.php
Code:
<?php defined('BASEPATH') OR exit('Access denied!');

/*
|--------------------------------------------------------------------------
| Application directory name
|--------------------------------------------------------------------------
|
|
|
*/
$config['app_url'] = 'admin';


/*
|--------------------------------------------------------------------------
| Load the global configuration file.
|--------------------------------------------------------------------------
*/
if (file_exists(CONFIGPATH . 'config.php')):
// Include the configuration file.
//
require(CONFIGPATH . 'config.php');

// Merge both $config arrays.
//
$config = array_merge($config, $config);

// Configure the application base url.
//
$config['base_url'] = $config['base_url'] . $config['app_url'];
endif;

/* End of file config.php */
/* Location: ./application/config/config.php */


application/config/database.php
Code:
<?php defined('BASEPATH') OR exit('Access denied!');

/*
|--------------------------------------------------------------------------
| Load the database configuration file.
|--------------------------------------------------------------------------
*/
if (file_exists(CONFIGPATH . 'database.php')):
// Include the database configuration file.
//
require(CONFIGPATH . 'database.php');
endif;

/* End of file database.php */
/* Location: ./application/config/database.php */


index.php
Code:
/*
|---------------------------------------------------------------
| CONFIG FOLDER NAME
|---------------------------------------------------------------
|
| This variable must contain the nome of your "config" folder.
| Include the path if the folder is not in the same  directory
| as this file.
|
*/
$config_path = '../system/config';

/*
* ---------------------------------------------------------------
*  Resolve the config path for increased reliability
* ---------------------------------------------------------------
*/

if (realpath($config_path) !== FALSE)
{
  $config_path = realpath($config_path).'/';
}

// ensure there's a trailing slash
$config_path = rtrim($config_path, '/').'/';

// Is the system path correct?
if ( ! is_dir($config_path))
{
  exit("Your config folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}


// Path to the config folder.
define('CONFIGPATH', str_replace("\\", "/", $config_path));



And i created a config folder inside my system folder that looks like this:
Quote:system
| codeigniter
| config
| config.php
| database.php

Inside this config folder i pasted both original config.php and database.php files, and i can have the same config file for multiple applications.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.