From 22ae718754bec50ef801a2a3d0195ae4a179a048 Mon Sep 17 00:00:00 2001 From: Tinsh Date: Sat, 5 Aug 2023 00:06:33 +0800 Subject: [PATCH] docs(ORM): strip redundant tabs or replace with 4 spaces --- modules/orm/guide/orm/examples/simple.md | 210 +++++++++--------- modules/orm/guide/orm/examples/validation.md | 216 +++++++++---------- modules/orm/guide/orm/filters.md | 64 +++--- modules/orm/guide/orm/index.md | 12 +- modules/orm/guide/orm/models.md | 14 +- modules/orm/guide/orm/relationships.md | 106 ++++----- modules/orm/guide/orm/upgrading.md | 6 +- modules/orm/guide/orm/using.md | 84 ++++---- modules/orm/guide/orm/validation.md | 142 ++++++------ 9 files changed, 427 insertions(+), 427 deletions(-) diff --git a/modules/orm/guide/orm/examples/simple.md b/modules/orm/guide/orm/examples/simple.md index b8abe92..73cd010 100644 --- a/modules/orm/guide/orm/examples/simple.md +++ b/modules/orm/guide/orm/examples/simple.md @@ -1,119 +1,119 @@ # Simple Examples -This is a simple example of a single ORM model, that has no relationships, but uses validation on the fields. +This is a simple example of a single ORM model, that has no relationships, but uses validation on the fields. ## SQL schema - CREATE TABLE IF NOT EXISTS `members` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `username` varchar(32) NOT NULL, - `first_name` varchar(32) NOT NULL, - `last_name` varchar(32) NOT NULL, - `email` varchar(127) DEFAULT NULL, - PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; + CREATE TABLE IF NOT EXISTS `members` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `username` varchar(32) NOT NULL, + `first_name` varchar(32) NOT NULL, + `last_name` varchar(32) NOT NULL, + `email` varchar(127) DEFAULT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; ## Model - - array( - array('not_empty'), - array('min_length', array(':value', 4)), - array('max_length', array(':value', 32)), - array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')), - ), - 'first_name' => array( - array('not_empty'), - array('min_length', array(':value', 4)), - array('max_length', array(':value', 32)), - array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')), - ), - 'last_name' => array( - array('not_empty'), - array('min_length', array(':value', 4)), - array('max_length', array(':value', 32)), - array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')), - ), - 'email' => array( - array('not_empty'), - array('min_length', array(':value', 4)), - array('max_length', array(':value', 127)), - array('email'), - ), - ); - } - } - -[!!] The array returned by `ORM::rules()` will be passed to a [Validation] object and tested when you call `ORM::save()`. + + array( + array('not_empty'), + array('min_length', array(':value', 4)), + array('max_length', array(':value', 32)), + array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')), + ), + 'first_name' => array( + array('not_empty'), + array('min_length', array(':value', 4)), + array('max_length', array(':value', 32)), + array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')), + ), + 'last_name' => array( + array('not_empty'), + array('min_length', array(':value', 4)), + array('max_length', array(':value', 32)), + array('regex', array(':value', '/^[-\pL\pN_.]++$/uD')), + ), + 'email' => array( + array('not_empty'), + array('min_length', array(':value', 4)), + array('max_length', array(':value', 127)), + array('email'), + ), + ); + } + } + +[!!] The array returned by `ORM::rules()` will be passed to a [Validation] object and tested when you call `ORM::save()`. [!!] Please notice that defining the primary key "id" in the model is not necessary. Also the table name in the database is plural and the model name is singular. ## Controller - where('first_name', '=', 'Peter')->find_all(); - - // Count records in the $members object - $members->count_all(); - - /** - * Example 2 - */ - - // Create an instance of a model - $member = ORM::factory('Member'); - - // Get a member with the user name "bongo" find() means - // we only want the first record matching the query. - $member->where('username', '=', 'bongo')->find(); - - /** - * Example 3 - */ - - // Create an instance of a model - $member = ORM::factory('Member'); - - // Do an INSERT query - $member->username = 'bongo'; - $member->first_name = 'Peter'; - $member->last_name = 'Smith'; - $member->save(); - - /** - * Example 4 - */ - - // Create an instance of a model where the - // table field "id" is "1" - $member = ORM::factory('Member', 1); - - // Do an UPDATE query - $member->username = 'bongo'; - $member->first_name = 'Peter'; - $member->last_name = 'Smith'; - $member->save(); - } - } + where('first_name', '=', 'Peter')->find_all(); + + // Count records in the $members object + $members->count_all(); + + /** + * Example 2 + */ + + // Create an instance of a model + $member = ORM::factory('Member'); + + // Get a member with the user name "bongo" find() means + // we only want the first record matching the query. + $member->where('username', '=', 'bongo')->find(); + + /** + * Example 3 + */ + + // Create an instance of a model + $member = ORM::factory('Member'); + + // Do an INSERT query + $member->username = 'bongo'; + $member->first_name = 'Peter'; + $member->last_name = 'Smith'; + $member->save(); + + /** + * Example 4 + */ + + // Create an instance of a model where the + // table field "id" is "1" + $member = ORM::factory('Member', 1); + + // Do an UPDATE query + $member->username = 'bongo'; + $member->first_name = 'Peter'; + $member->last_name = 'Smith'; + $member->save(); + } + } [!!] $member will be a PHP object where you can access the values from the query e.g. echo $member->first_name diff --git a/modules/orm/guide/orm/examples/validation.md b/modules/orm/guide/orm/examples/validation.md index 0510a45..40ead7e 100644 --- a/modules/orm/guide/orm/examples/validation.md +++ b/modules/orm/guide/orm/examples/validation.md @@ -4,134 +4,134 @@ This example will create user accounts and demonstrate how to handle model and c ## SQL schema - CREATE TABLE IF NOT EXISTS `members` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `username` varchar(32) NOT NULL, - `password` varchar(100) NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; + CREATE TABLE IF NOT EXISTS `members` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `username` varchar(32) NOT NULL, + `password` varchar(100) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1; ## Model - - array( - array('not_empty'), - array('min_length', array(':value', 4)), - array('max_length', array(':value', 32)), - array(array($this, 'username_available')), - ), - 'password' => array( - array('not_empty'), - ), - ); - } - - public function filters() - { - return array( - 'password' => array( - array(array($this, 'hash_password')), - ), - ); - } - - public function username_available($username) - { - // There are simpler ways to do this, but I will use ORM for the sake of the example - return ORM::factory('Member', array('username' => $username))->loaded(); - } - - public function hash_password($password) - { - // Do something to hash the password - } - } + + array( + array('not_empty'), + array('min_length', array(':value', 4)), + array('max_length', array(':value', 32)), + array(array($this, 'username_available')), + ), + 'password' => array( + array('not_empty'), + ), + ); + } + + public function filters() + { + return array( + 'password' => array( + array(array($this, 'hash_password')), + ), + ); + } + + public function username_available($username) + { + // There are simpler ways to do this, but I will use ORM for the sake of the example + return ORM::factory('Member', array('username' => $username))->loaded(); + } + + public function hash_password($password) + { + // Do something to hash the password + } + } ## HTML Form Please forgive my slightly ugly form. I am trying not to use any modules or unrelated magic. :) -
- - -