Giter VIP home page Giter VIP logo

codeigniter-my-model's Introduction

my_model

Super simple Codeigniter MY_Model for generic database operations

Why?

We want our models to be slim. Commonly used database operations should be inside MY_Model where every model file can extend and use.

How to Use

  1. Copy MY_Model.php to application/core

  2. Extend MY_Model instead of CI_Model

    class Some_model extends MY_Model { }

  3. Set table name to use inside your models

    protected $TABLE = "mytable";

  4. Set custom primary key

    protected $PKEY = "custom_pkey";

  5. Call MY_Model functions from model like this. Make sure your model extends MY_Model.

    $result = $this->get(1)->row();

  6. Call MY_Model functions from controller like this. Make sure your model is loaded and extends MY_Model.

    $result = $this->some_model->get(1)->row();

Note If you don't specify a table name, MY_Model will guess table name by pluralizing model class name. See _get_table()

Note If you don't set custom primary key, "id" will be used as primary key.

#To Do's

  • Option to record date time stamps to database write, update and delete operations
  • Option to enable soft delete of data (data are tagged as deleted but not entirely deleted)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.