Welcome Guest, Not a member yet? Register   Sign In
MCI
#1

[eluser]dinhtrung[/eluser]
Hi all,

I'd like to introduce my CI 2.0 code base.

https://bitbucket.org/dinhtrung/mcirepo

To try:

1. dump the db in /sql/ folder.
2. Create a sample database table.
3. Go to <app>/mci/module/generator
4. Choose the table, and the template for module.
5. Submit.

Basic CRUD function are supported.

Module should have 2 controller, one extends Frontend and one extends SiteBackend.

The function _form() in controller use Form Generation Library to produce the copy, create and update form.

Write your select, join in your _listview() and use parent _listview() to generate pagination links and data in view files.

You can use $this->override to add extra variables into views.

Permission control can be configured through Sitebackend::_permission(), SItebackend::module_access() and Sitebackend::module_menu().

SiteModel has after_create(), before_create(), after_update(), before_update()... for modify data after main insert/update/delete.

I'll write detail docs later.
#2

[eluser]Vheissu[/eluser]
Nice work bro. Downloading now and checking this out later on.
#3

[eluser]tieungao[/eluser]
i downloaded and this not work.

only the link http://host.com/dinhtrung/ work

other link show empty page.
#4

[eluser]dinhtrung[/eluser]
## Virtual Site Support ##
I configure the hosts file in OS to some hostname to localhost. For eg,
127.0.0.1 localhost dev1.localhost dev2.localhost dev3.localhost

To use the same code base for multiple project, I change the database configuration file:

// You can override Database here
$db['dev1.localhost']['database'] = 'mcirepo';
$db['dev2.localhost']['database'] = 'test1';
$db['dev3.localhost']['database'] = 'test2';

Each project shoult have its own Module location, so I add similar declaration into config/config.php for Modular Extension's module_locations variable:

$locations = array();
$locations[$hostname] = array();
/* You can override locations based on hostname here */
$locations["dev1.localhost"] = array(APPPATH.'cms/' => '../cms/');
$locations["dev2.localhost"] = array(APPPATH.'eshop/' => '../eshop/');
$locations["dev3.localhost"] = array(APPPATH.'myproject/' => '../myproject/');
$config['modules_locations'] = array_merge($locations[$hostname], array( APPPATH.'modules/' => '../modules/'));

So beside the "modules" directory, I have other module dir for my project.

## Override Views ##

**Notice**: I have bypass strict checking for missing view file. I use log_message() instead of show_error(), so if you missing some views, the system won't show error out.

MCI support override views at multiple level. For example, I access http://host/module/controller/method/first_id/second_id, and call $this->load->view("someview"), the following views will be load:

1 - themes/[current]/[module]/views/module-controller-someview
2 - [project_module_dir]/[module]/views/module-controller-someview
3 - views/module-controller-someview
4 - themes/[current]/[module]/views/module-someview
5 - [project_module_dir]/[module]/views/module-someview
6 - views/module-someview
7 - themes/[current]/[module]/views/someview
8 - [project_module_dir]/[module]/views/someview
9 - views/someview

Sounds similar to Drupal, isn't it? :p

## Override Controller ##

MCI ship with 3 Controllers:
* MY_Controller: provide basic initialization. Provide _display() function, to set main page content, and print it out. Some basic variable helpers:
* $this->module, $this->controller, $this->method: Current module, controller and method.
* $this->first_id, $this->second_id : The first and second argument in URI, after method segment.
* $this->base : Serve as an ID for current module and controller. It used to create prefix for div elements and permission checking resource. For example, a module named pages and controller named pages_admin should have base "pages-pages_admin-", while controller named pages will have "pages-" .
* $this->base_url : Provide the base URL for current module controller. Use to create links and other stuff.
* Frontend : To create public pages. It provide basic listing and view detail methods:
* page() : Browse the database table, provided by a child class of Basemodel or Sitemodel.
* _listview($start = 0): Create variable $data_rows, contains the retrieved database rows, and set the pagination class total rows. This is where you should write your SELECT and JOIN expression, if any.
* item() : View detail information for a table row.
* _item() : Retrieve a row from database table.

* SiteBackend : To create admin UI. It extends from Frontend, and provide methods for create(), update() and copy() based on Form Generation Library.
* _form() : This is where you should write your form.
* copy(), create(), update(): Entry methods, call to _form() to perform data CRU.
* delete(): To delete a row.
* action() : This method serve as an entry point to other callback methods, to perform batch operation. The ids of db table contain in $_POST['selection'], and the process callback is specified in $_POST['process_method']. For e.g
* _action_delete() is called when $_POST['process_method'] = "delete", to delete multiple rows. It could use $this->selection to retrieve the selection of user, in $_POST['selection'], and $this->process_method = "delete".
* _action_update() is called when $_POST['process_method'] = "update/myinfo", but because $_POST['process_method'] has a "/" character, so this method has 2 var: $this->process_method = "update", and $this->process_param = "myinfo".
* _action_update_data() is called when $_POST['process_method'] = "update_data/a=1&b=2&c=3". $this->process_method = "update_data", $this->process_param = "a=1&b=2&c=3".

Every methods in MCI Controller can be override data before load view, with $this->override() array. The view can be override by set $this->viewfile per method.
#5

[eluser]tieungao[/eluser]
after download your zip, i unzip this and go to assets to create 2 directories : logs and cache.

and then i modify database to test with 2 database first.

I go to http://localhost/dinhtrung/

this show a page have form to input admin and password. After submit this form i go to blank page with link : http://localhost/dinhtrung/user/login

Can you provide step by step how to install and configure you apps in order to work on localhost.

Thank you.
#6

[eluser]dinhtrung[/eluser]
@tieungao: You should enable mod_rewrite and add .htaccess file to hide the "index.php" part on your URL.
#7

[eluser]tieungao[/eluser]
yes i put one .htaccess and the code work. Btw, what the password for user "system". When login to admin interface i see that have some tab to create block admin, user role,..

Let make a example i want to build a new site have cms content and frontend display something with this system.

I still not imaging how to do that step by step. Maybe you need a good document for instruction new user about using your system.

Thank again for nice code.

PS : i have some offer job about modifying SE 4 (Social Engine). If you are interesting in please let me know by email : [email protected] or skype : quanphp1
#8

[eluser]tieungao[/eluser]
when i go to : http://localhost/dinhtrung/dashboard/create

i got some errors :

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Dashboard::$model

Filename: core/SiteBackend.php

Line Number: 55
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Dashboard::$model

Filename: core/SiteBackend.php

Line Number: 69
An Error Was Encountered

model: No model specified
#9

[eluser]dinhtrung[/eluser]
Thank you for your feedback.

The user and pass to login to the system is :

User: system
Pass: admin.

### Models ###

The idea here is one module should have a BaseModel or Sitemodel instance. Basemodel is extends from MY_Model, from Jamie Rumbelow, which associate one dbtable with one Model.

BaseModel provide further feature, like Form Generation library Create and Update compatible methods. In this class, you must specify the DBForge table structure. If your Sitebackend Controller use Basemodel as its model, you could use its install() method to automatic create the db structure in CI DBForge way. Further, it provide options() methods, which return a list of key - value as an helper for quickly retrieve the list of select items. Also, a checkgroup() methods, to provide an array of data rows, with structure support FGL checkgroups() and radiogroups() method.

SiteModel is designed for better flexible database. In development environment, it just query the db for table structure, and automatically adapt itself to it. I wrote this to adapt the change in my DB, without re-declare the basemodel dbfields structure. If you turn off development environment, Sitemodel will cache db table structure, so performance will be the same as Basemodel.

In Basemodel and Sitemodel, there is 3 more important method: db2form(), form2db() and db2view().

* db2form(): Convert data row from database to form, to populate the form in update method. For example, convert the date time format from MySQL to English.
* form2db(): Filter out the data sent from form, keep only fields that exists in the db table. Also, you can use it for data conversion, and do some "trigger" in the db.
* db2view(): Convert data between database and view. You can format raw data from DB, to something else in your viewfile. The $scope could be "table" and "item", which used in page() and item() function of Frontend.




Theme © iAndrew 2016 - Forum software by © MyBB