Download the PHP package faqzul/codeigniter-crud-model without Composer
On this page you can find all versions of the php package faqzul/codeigniter-crud-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download faqzul/codeigniter-crud-model
More information about faqzul/codeigniter-crud-model
Files in faqzul/codeigniter-crud-model
Package codeigniter-crud-model
Short Description Create one model for all CodeIgniter controllers.
License MIT
Homepage https://github.com/FaqZul
Informations about the package codeigniter-crud-model
CodeIgniter-CRUD-Model
Create one model for all CodeIgniter controllers, or You can extends this class in Your model class.
Getting Started
Composer
Prerequisites
- PHP version 5.6 or newer is recommended.
It should work on 5.4.8 as well, but we strongly advise you NOT to run such old versions of PHP, because of potential security and performance issues, as well as missing features. - CodeIgniter 3.x
Configuration
-
Change the following line in the
application/config/autoload.php
file for use in Your controller class. - Change the following line in the
application/config/config.php
file for extends in Your model class.
Setting CRUD Preferences
There are 4 different preferences available to suit Your needs. You can set it up manually as described here, or automatically via the preferences stored in Your configuration file, described below:
Preferences are set by passing an array of preference values to the crud initialize method. Here is an example of how You might set some preferences:
:information_source: Note
Most of the preferences have default values that will be used if You do not set them.Setting CRUD Preferences in a Config File
If You prefer not to set preferences using the above method, You can instead put them into a config file. Simply create a new file called the crud.php, add the $config array in that file. Then save the file at config/crud.php and it will be used automatically. You will NOT need to use the
$this->crud->initialize()
method if You save Your preferences in a config file.CRUD Preferences
Here is a list of all the options that can be set when using the crud class.
Preferences | Default Value | Options | Description |
---|---|---|---|
dbgroup | default | None | Lets You choose which connection group to make active |
delete_record | TRUE | TRUE or FALSE (boolean). |
TRUE: Your data will be deleted permanently. FALSE: Your data able to be recovered (un-deleted). |
insert_id_key | NULL | None | If using the PDO driver with PostgreSQL, or using the Interbase driver, this preference which specifies the appropriate sequence to check for the insert id. |
log_query | FALSE | TRUE or FALSE (boolean). |
Save the last query that was run. |
track_trans | FALSE | TRUE or FALSE (boolean). |
To know the data (when and who) created or updated. |
Usage
createData
:information_source: Note
To use $this->crud->insert_id() or $this->crud->insert_ids() if using the PDO driver with PostgreSQL, or using the Interbase driver, requires preferenceinsert_id_key
which specifies the appropriate sequence to check for the insert id.
readData
:information_source: Note
Now, you can use queries JOIN, LIKE, WHERE more specific. See ChangeLog
If preferencedelete_record
FALSE, automatically addWHERE TABLENAME_delete_date IS NULL
in Your query.updateData
deleteData
extends
:information_source: Note
For the sake of simplicity in this example we’re using$_POST
directly. This is generally bad practice, and a more common approach would be to use the Input Library$this->input->post('title')
.
Class Reference
createData($table, $data [, $callback = FALSE ])
- Parameters:
- $table (string) - Table name.
- $data (array) - An associative array of field/value pairs.
- Returns:
$callback = FALSE
TRUE on success, FALSE on failure.$callback = TRUE
- code (int) - SQL error code.
- insert_id (int) - The insert ID number when performing database inserts.
- insert_ids (array) - Insert ID from insert_batch.
- message (string) - SQL error message.
- Return Type: mixed. createDataQuery($table, $data)
- Parameters:
- $table (string) - Table name.
- $data (array) - An associative array of field/value pairs.
- Returns: Compiles an INSERT statement and returns it as a string.
- Return Type: string. readData($select, $from [, $where = NULL [, $joinTable = NULL [, $groupBy = NULL [, $orderBy = NULL [, $limit = NULL ] ] ] ] ])
- Parameters:
- $select (string) - The SELECT portion of a query.
- $from (mixed) - Table name(s); array or string.
- $where (mixed) - The WHERE clause; array or string.
- $joinTable (array) - An associative array of table/condition pairs.
- $groupBy (mixed) - Field(s) to group by; array or string.
- $orderBy (string) - Field to order by. The order requested - ASC, DESC or random.
- $limit (array) - Adds LIMIT and OFFSET clauses to a query.
array(10, 20)
.
- Key
0
(int) - Number of rows to limit the result to.- Key
1
(int) - Number of rows to skip.- Returns: There are several ways to generate query results:
- Result Arrays.
- Result Rows.
- Custom Result Objects.
- Result Helper Methods.
- Return Type: CI_DB_result. readDataQuery($select, $from [, $where = NULL [, $joinTable = NULL [, $groupBy = NULL [, $orderBy = NULL [, $limit = NULL ] ] ] ] ])
- Parameters:
- $select (string) - The SELECT portion of a query.
- $from (mixed) - Table name(s); array or string.
- $where (mixed) - The WHERE clause; array or string.
- $joinTable (array) - An associative array of table/condition pairs.
- $groupBy (mixed) - Field(s) to group by; array or string.
- $orderBy (string) - Field to order by. The order requested - ASC, DESC or random.
- $limit (array) - Adds LIMIT and OFFSET clauses to a query.
array(10, 20)
.
- Key
0
(int) - Number of rows to limit the result to.- Key
1
(int) - Number of rows to skip.- Returns: Compiles a SELECT statement and returns it as a string.
- Return Type: string. updateData($table, $data, $where [, $callback = FALSE ])
- Parameters:
- $table (string) - Table name.
- $data (array) - An associative array of field/value pairs.
- $where (mixed) - The WHERE clause; array or string.
- Returns:
$callback = FALSE
TRUE on success, FALSE on failure.$callback = TRUE
error() method.- Return Type: mixed. updateDataQuery($table, $data, $where)
- Parameters:
- $table (string) - Table name.
- $data (array) - An associative array of field/value pairs.
- $where (mixed) - The WHERE clause; array or string.
- Returns: Compiles an UPDATE statement and returns it as a string.
- Return Type: string. deleteData($table, $where [, $callback = FALSE ])
- Parameters:
- $table (string) - Table name.
- $where (mixed) - The WHERE clause; array or string.
- Returns:
$callback = FALSE
TRUE on success, FALSE on failure.$callback = TRUE
error() method.- Return Type: mixed. deleteDataQuery($table, $where)
- Parameters:
- $table (string) - Table name.
- $where (mixed) - The WHERE clause; array or string.
- Returns: Compiles a DELETE statement and returns it as a string.
- Return Type: string. error()
- Returns:
- code (int) - SQL error code.
- message (string) - SQL error message.
- Return Type: array. error_code()
- Returns: SQL error code.
- Return Type: int. error_message()
- Returns: SQL error message.
- Return Type: string. insert_id()
- Returns: The insert ID number when performing database inserts.
- Return Type: int. insert_ids()
- Returns: The insert ID number when performing database inserts.
- Return Type: array.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Muhammad Faqih Zulfikar - Developer
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.