The Besc_crud class provides functionality for creating, reading, updating and deleting database records, as well as rendering views for listing and editing data.

Properties

ci
object

CodeIgniter instance

db_name
string

Database name

db_table
string

Database table name

db_primary_key
string

Primary key column name

db_columns
array

Array of column definitions

list_columns
array

Array of column names to show in list view

filter_columns
array

Array of column names to allow filtering on

title
string

Title for the CRUD views

base_url
string

Base URL for CRUD operations

Methods

__construct()

Constructor method. Initializes CodeIgniter dependencies.

execute($per_page = ROWS_PER_PAGE_OF_TABLE)

Main method to handle CRUD operations based on the current state.

per_page
integer

Number of rows per page for list view

render_list($ajax = false)

Renders the list view.

ajax
boolean

Whether this is an AJAX request

render_edit()

Renders the edit view for adding or editing a record.

delete()

Deletes a record.

insert()

Inserts a new record.

update()

Updates an existing record.

validate()

Validates submitted form data.

imageupload()

Handles image file uploads.

fileupload()

Handles general file uploads.

imagecrop()

Crops an uploaded image.

Usage

$crud = new Besc_crud();

$crud->table('users');
$crud->primary_key('id');
$crud->columns([
  'id' => ['type' => 'hidden'],
  'name' => ['type' => 'text'],
  'email' => ['type' => 'text']
]);

$output = $crud->execute();

This initializes a CRUD interface for the “users” table. The execute() method handles the current operation (list, add, edit, etc) and returns the appropriate view.