CodeIgniter Application Structure

EDIT:

What is the best way to structure complex applications with CodeIgniter? To make this question more specific, it’s possible just to focus on structuring the controllers: if you have a user controller, what should all the functions be in this single file? In other words, you may have controller actions that are tied to specific views, but also auxiliary functions.

ORIGINAL QUESTION: Given a complex application, with users, transactions, products, does it make sense to have a controller for each of them? And since each of them corresponds to the database table, is there a corresponding model for each of them? I think it is, but the application I am working on now consists of one 3000 line controller and one 3000 line model. I just want to check the standard practice regarding CI and application structure.

+1
source share
4 answers

I would like to share my application structure here.

. 1 mysql. MY_Model, system/application/libraries/. get_detail, get_list, get_total, get_all, insert, update delete. var, , :

class Some_table_model extends MY_Model {
  function Some_table_model()
  {
    $this->tablename = 'some_table';
    $this->primary_key = 'id';
  }

}

: var , . , , MY_Model.

. , :

function Product extends Controller {
  function index()
  {
    //display product list, paginated
  }
  function admin()
  {
    //protected by session
    //display product list for admin, paginated
    //handle POST request to delete a product or products
  }
  function form()
  {
    //protected by session
    //handle add/edit product for admin
  }
}

. 3 :

product_list.php
product_admin.php
product_form.php

subdir, , :

system/application/views/front/product.php
system/application/views/admin/product_list.php
system/application/views/admin/product_form.php

, , Product, :

function category_admin()
{
  //get parameter
  //...
  //process data
  //...
  //redirect or load view
  //...
}

function category_form()
{
  //get parameter
  //...
  //process data
  //...
  //redirect or load view
  //...
}

, . , CodeIgniter.

+3

. URL-, .

, 1 1 , DB 4 .

0

, - :

user_model:
 add_user();
 delete_user();
 ...

products:
 add_product();
 delete_product();
 ...

transaction:
 ...
 ...

.

. .

products:
 add_product();
 show_product();
 get_product();
 ...

users: 
 add_user();
 delete_user();
 ...

.. , / , .

, , , .

0

, Matchbox.

Matchbox:

Matchbox is a set of advanced libraries that allows you to organize your application in small components (modules). These modules have several advantages, the main one being portability. Modules are stored in their own folders and therefore they can be reused in other applications or shared between users by copying only one folder.

This allows you to really organize content by placing related models and controllers in the same folder.

0
source

Source: https://habr.com/ru/post/1775089/


All Articles