Skip to content

Commit

Permalink
Update documentation code samples (#5039)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan authored Aug 30, 2021
1 parent a630617 commit ffcf115
Show file tree
Hide file tree
Showing 74 changed files with 762 additions and 922 deletions.
2 changes: 1 addition & 1 deletion env
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# app.sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler'
# app.sessionCookieName = 'ci_session'
# app.sessionExpiration = 7200
# app.sessionSavePath = NULL
# app.sessionSavePath = null
# app.sessionMatchIP = false
# app.sessionTimeToUpdate = 300
# app.sessionRegenerateDestroy = false
Expand Down
11 changes: 4 additions & 7 deletions user_guide_src/source/cli/cli_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,9 @@ be familiar with when creating your own commands. It also has a :doc:`Logger </g

A convenience method to maintain a consistent and clear error output to the CLI::

try
{
try {
. . .
}
catch (\Exception $e)
{
} catch (\Exception $e) {
$this->showError($e);
}

Expand All @@ -208,8 +205,8 @@ be familiar with when creating your own commands. It also has a :doc:`Logger </g
A method to calculate padding for $key => $value array output. The padding can be used to output a will formatted table in CLI::

$pad = $this->getPad($this->options, 6);
foreach ($this->options as $option => $description)
{

foreach ($this->options as $option => $description) {
CLI::write($tab . CLI::color(str_pad($option, $pad), 'green') . $description, 'yellow');
}

Expand Down
9 changes: 3 additions & 6 deletions user_guide_src/source/cli/cli_library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ Instead it prints it to the screen wherever the cursor is currently. This allows
the same line, from different calls. This is especially helpful when you want to show a status, do something, then
print "Done" on the same line::

for ($i = 0; $i <= 10; $i++)
{
for ($i = 0; $i <= 10; $i++) {
CLI::print($i);
}

Expand Down Expand Up @@ -172,8 +171,7 @@ every line after the first line, so that you will have a crisp column edge on th
// to determine the width of the left column
$maxlen = max(array_map('strlen', $titles));

for ($i=0; $i < count($titles); $i++)
{
for ($i = 0; $i < count($titles); $i++) {
CLI::write(
// Display the title on the left of the row
$titles[$i] . ' ' .
Expand Down Expand Up @@ -227,8 +225,7 @@ pass ``false`` as the first parameter and the progress bar will be removed.
$totalSteps = count($tasks);
$currStep = 1;

foreach ($tasks as $task)
{
foreach ($tasks as $task) {
CLI::showProgress($currStep++, $totalSteps);
$task->run();
}
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/cli/cli_request.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Returns the value of a specific command line argument deemed to be an option::

// command line: php index.php users 21 profile --foo bar
echo $request->getOption('foo'); // bar
echo $request->getOption('notthere'); // NULL
echo $request->getOption('notthere'); // null

**getOptionString()**

Expand Down
50 changes: 25 additions & 25 deletions user_guide_src/source/database/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ prototype::
'database' => 'database_name',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => TRUE,
'DBDebug' => TRUE,
'pConnect' => true,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'strictOn' => FALSE,
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
];

Expand Down Expand Up @@ -80,14 +80,14 @@ These failovers can be specified by setting the failover for a connection like t
'database' => '',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => TRUE,
'DBDebug' => TRUE,
'pConnect' => true,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'strictOn' => FALSE
'encrypt' => false,
'compress' => false,
'strictOn' => false,
],
[
'hostname' => 'localhost2',
Expand All @@ -96,14 +96,14 @@ These failovers can be specified by setting the failover for a connection like t
'database' => '',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => TRUE,
'DBDebug' => TRUE,
'pConnect' => true,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'strictOn' => FALSE
'encrypt' => false,
'compress' => false,
'strictOn' => false,
]
];

Expand All @@ -123,14 +123,14 @@ example, to set up a "test" environment you would do this::
'database' => 'database_name',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => TRUE,
'DBDebug' => TRUE,
'pConnect' => true,
'DBDebug' => true,
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'compress' => FALSE,
'encrypt' => FALSE,
'strictOn' => FALSE,
'compress' => false,
'encrypt' => false,
'strictOn' => false,
'failover' => []
);

Expand Down Expand Up @@ -188,8 +188,8 @@ Explanation of Values:
**DBPrefix** An optional table prefix which will added to the table name when running
:doc:`Query Builder <query_builder>` queries. This permits multiple CodeIgniter
installations to share one database.
**pConnect** TRUE/FALSE (boolean) - Whether to use a persistent connection.
**DBDebug** TRUE/FALSE (boolean) - Whether database errors should be displayed.
**pConnect** true/false (boolean) - Whether to use a persistent connection.
**DBDebug** true/false (boolean) - Whether database errors should be displayed.
**charset** The character set used in communicating with the database.
**DBCollat** The character collation used in communicating with the database

Expand All @@ -201,18 +201,18 @@ Explanation of Values:
**schema** The database schema, default value varies by driver. Used by PostgreSQL and SQLSRV drivers.
**encrypt** Whether or not to use an encrypted connection.

- 'sqlsrv' and 'pdo/sqlsrv' drivers accept TRUE/FALSE
- 'sqlsrv' and 'pdo/sqlsrv' drivers accept true/false
- 'MySQLi' and 'pdo/mysql' drivers accept an array with the following options:

- 'ssl_key' - Path to the private key file
- 'ssl_cert' - Path to the public key certificate file
- 'ssl_ca' - Path to the certificate authority file
- 'ssl_capath' - Path to a directory containing trusted CA certificates in PEM format
- 'ssl_cipher' - List of *allowed* ciphers to be used for the encryption, separated by colons (':')
- 'ssl_verify' - TRUE/FALSE; Whether to verify the server certificate or not ('MySQLi' only)
- 'ssl_verify' - true/false; Whether to verify the server certificate or not ('MySQLi' only)

**compress** Whether or not to use client compression (MySQL only).
**strictOn** TRUE/FALSE (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL
**strictOn** true/false (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL
while developing an application.
**port** The database port number. To use this value you have to add a line to the database config array.
::
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/database/connecting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Available Parameters
--------------------

#. The database group name, a string that must match the config class' property name. Default value is ``$config->defaultGroup``.
#. TRUE/FALSE (boolean). Whether to return the shared connection (see
#. true/false (boolean). Whether to return the shared connection (see
Connecting to Multiple Databases below).

Manually Connecting to a Database
Expand Down
12 changes: 4 additions & 8 deletions user_guide_src/source/database/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ Standard Query With Multiple Results (Object Version)

::

$query = $db->query('SELECT name, title, email FROM my_table');
$query = $db->query('SELECT name, title, email FROM my_table');
$results = $query->getResult();

foreach ($results as $row)
{
foreach ($results as $row) {
echo $row->title;
echo $row->name;
echo $row->email;
Expand All @@ -51,8 +50,7 @@ Standard Query With Multiple Results (Array Version)
$query = $db->query('SELECT name, title, email FROM my_table');
$results = $query->getResultArray();

foreach ($results as $row)
{
foreach ($results as $row) {
echo $row['title'];
echo $row['name'];
echo $row['email'];
Expand Down Expand Up @@ -102,8 +100,7 @@ means of retrieving data::

$query = $db->table('table_name')->get();

foreach ($query->getResult() as $row)
{
foreach ($query->getResult() as $row) {
echo $row->title;
}

Expand All @@ -124,4 +121,3 @@ Query Builder Insert

$db->table('mytable')->insert($data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')

34 changes: 13 additions & 21 deletions user_guide_src/source/database/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ you are currently connected to. Example::

$tables = $db->listTables();

foreach ($tables as $table)
{
foreach ($tables as $table) {
echo $table;
}

Expand All @@ -35,10 +34,9 @@ Determine If a Table Exists
**$db->tableExists();**

Sometimes it's helpful to know whether a particular table exists before
running an operation on it. Returns a boolean TRUE/FALSE. Usage example::
running an operation on it. Returns a boolean true/false. Usage example::

if ($db->tableExists('table_name'))
{
if ($db->tableExists('table_name')) {
// some code...
}

Expand All @@ -60,8 +58,7 @@ two ways:

$fields = $db->getFieldNames('table_name');

foreach ($fields as $field)
{
foreach ($fields as $field) {
echo $field;
}

Expand All @@ -70,8 +67,7 @@ calling the function from your query result object::

$query = $db->query('SELECT * FROM some_table');

foreach ($query->getFieldNames() as $field)
{
foreach ($query->getFieldNames() as $field) {
echo $field;
}

Expand All @@ -81,10 +77,9 @@ Determine If a Field is Present in a Table
**$db->fieldExists()**

Sometimes it's helpful to know whether a particular field exists before
performing an action. Returns a boolean TRUE/FALSE. Usage example::
performing an action. Returns a boolean true/false. Usage example::

if ($db->fieldExists('field_name', 'table_name'))
{
if ($db->fieldExists('field_name', 'table_name')) {
// some code...
}

Expand All @@ -108,8 +103,7 @@ Usage example::

$fields = $db->getFieldData('table_name');

foreach ($fields as $field)
{
foreach ($fields as $field) {
echo $field->name;
echo $field->type;
echo $field->max_length;
Expand Down Expand Up @@ -141,11 +135,10 @@ Usage example::

$keys = $db->getIndexData('table_name');

foreach ($keys as $key)
{
echo $key->name;
echo $key->type;
echo $key->fields; // array of field names
foreach ($keys as $key) {
echo $key->name;
echo $key->type;
echo $key->fields; // array of field names
}

The key types may be unique to the database you are using.
Expand All @@ -160,8 +153,7 @@ Usage example::

$keys = $db->getForeignKeyData('table_name');

foreach ($keys as $key)
{
foreach ($keys as $key) {
echo $key->constraint_name;
echo $key->table_name;
echo $key->column_name;
Expand Down
Loading

0 comments on commit ffcf115

Please sign in to comment.