wordpressdev / my_model Goto Github PK
View Code? Open in Web Editor NEWThis project forked from carternerds/my_model
A My_Model class to provide CRUD functionality for other Model cllasses to inherit actions.
License: Other
This project forked from carternerds/my_model
A My_Model class to provide CRUD functionality for other Model cllasses to inherit actions.
License: Other
A My_Model class to provide CRUD functionality for other Model classes to inherit actions. Extending Class ************************************************************************************** A model class would extend the My_Model class in the following way class Posts extends MY_Model{ function __construct() { parent::__construct(); /*************************************** Set the model info ***************************************/ //Table name $this->table_name = "posts"; //Primary Key $this->primary_key = "post_id"; //Default order by $this->order_by = "post_id"; //Default sort direction $this->sort = "desc"; //Required fields $this->required_fields = array( "post_title", "post_body", "post_pubdate", "post_author", "post_slug" ); } } ====================================================================================== Get ************************************************************************************** Intended to provide the majority of get requests ************************************************************************************** //Get all entries $this->posts->get(); //Get a single entry by it's id $this->posts->get(1); //Get multiple entries $options['post_id'] = array(1,2); $this->posts->get($options); //Get all values sorted in DESC order $this->posts->sort = "desc"; $this->posts->get(); //Select all entries return a specific field $this->posts->get("post_id"); //Select all entries return multiple fields $options['select'] = array("post_title", "post_id"); $this->posts->get($options); //Select all with a condition $options['where'] = array("post_title" => "This is my first post"); $this->posts->get($options); //Select all with a comparison condition $options['where'] = array("post_pubdate <" => '2011-12-18'); $this->posts->get($options); //Select all like (and like) $options['like'] = array("post_author" => "Some", "post_body" => "Lorem"); $this->posts->get($options); //Select all like (or like) $options['or_like'] = array("post_author" => "Some", "post_body" => "Lorem"); $this->posts->get($options); //Get all and return as a key value array $options['key_value'] = array("post_title", "post_author"); $this->posts->get($options); //Select all with a limit and offset $this->posts->limit = 10; $this->posts->offset = 20; $this->posts->get(); ====================================================================================== Save ************************************************************************************** Intended to provide the majority of insert and update requests Adding required fields to the post array will validate -their presence and that they have a value //Required fields example $this->required_fields = array( "post_title", "post_body", "post_pubdate", "post_author", "post_slug" ); When saving an entry fields will be checked to ensure they exist. ************************************************************************************** //Save a single entry $data["post_title"] = "Post title"; $data["post_body"] = "Hello dolor sit amet, consectetur adipiscing elit."; $data["post_pubdate"] = "2012-01-27 16:57:48"; $data["post_author"] ="Paul Beardsell"; $data["post_slug"] = "post-title"; $insert_id = $this->posts->save($data); //Save a multiple entries $data[0]["post_title"] = "Post title"; $data[0]["post_body"] = "Hello dolor sit amet, consectetur adipiscing elit."; $data[0]["post_pubdate"] = "2012-01-27 16:57:48"; $data[0]["post_author"] ="Paul Beardsell"; $data[0]["post_slug"] = "post-title"; $data[1]["post_title"] = "Post title 2"; $data[1]["post_body"] = "Hello dolor sit amet, consectetur adipiscing elit."; $data[1]["post_pubdate"] = "2012-01-27 16:57:48"; $data[1]["post_author"] ="Paul Beardsell"; $data[1]["post_slug"] = "post-title-2"; $insert_id_array = $this->posts->save($data); //Update an entry $data["post_title"] = "This is the post title"; $data["post_slug"] = "this-is-the-post-title"; $this->posts->save($data, 1); ====================================================================================== Delete ************************************************************************************** Intended to provide the majority of delete requests ************************************************************************************** //Delete a single entry $this->posts->delete(1); //Delete a multiple entries $this->posts->delete(array(1,2)); ///////////////////////////////////////////////////////////////////////////////////// Inspiration from: Jamie Rumbelow @jamierumbelow Joost van Veen @joostvanveen /////////////////////////////////////////////////////////////////////////////////////
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.