-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8276 from kenjis/fix-docs-db-utils
docs: fix Database Utility Class `getXMLFromResult()`
- Loading branch information
Showing
4 changed files
with
50 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,53 @@ | ||
######### | ||
Utilities | ||
######### | ||
###################### | ||
Database Utility Class | ||
###################### | ||
|
||
The Database Utility Class contains methods that help you manage your database. | ||
|
||
.. contents:: | ||
:local: | ||
:depth: 2 | ||
|
||
******************* | ||
Get XML from Result | ||
******************* | ||
****************************** | ||
Initializing the Utility Class | ||
****************************** | ||
|
||
getXMLFromResult() | ||
================== | ||
Load the Utility Class as follows: | ||
|
||
This method returns the xml result from database result. You can do like this: | ||
.. literalinclude:: utilities/002.php | ||
:lines: 2- | ||
|
||
You can also pass another database group to the DB Utility loader, in case | ||
the database you want to manage isn't the default one: | ||
|
||
.. literalinclude:: utilities/003.php | ||
:lines: 2- | ||
|
||
In the above example, we're passing a database group name as the first | ||
parameter. | ||
|
||
**************************** | ||
Using the Database Utilities | ||
**************************** | ||
|
||
Export a Query Result as an XML Document | ||
======================================== | ||
|
||
Permits you to generate an XML file from a query result. The first | ||
parameter expects a query result object, the second may contain an | ||
optional array of config parameters. Example: | ||
|
||
.. literalinclude:: utilities/001.php | ||
|
||
and it will get the following xml result:: | ||
and it will get the following xml result when the ``mytable`` has columns ``id`` and ``name``:: | ||
|
||
<root> | ||
<element> | ||
<id>1</id> | ||
<name>bar</name> | ||
</element> | ||
</root> | ||
|
||
.. important:: This method will NOT write the XML file for you. It | ||
simply creates the XML layout. If you need to write the file | ||
use the :php:func:`write_file()` helper. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<?php | ||
|
||
class MyModel extends \CodeIgniter\Model | ||
{ | ||
protected $table = 'foo'; | ||
protected $primaryKey = 'id'; | ||
} | ||
$db = db_connect(); | ||
$dbutil = \Config\Database::utils(); | ||
|
||
$model = new MyModel(); | ||
$query = $db->query('SELECT * FROM mytable'); | ||
|
||
$util = \CodeIgniter\Database\Config::utils(); | ||
$config = [ | ||
'root' => 'root', | ||
'element' => 'element', | ||
'newline' => "\n", | ||
'tab' => "\t", | ||
]; | ||
|
||
echo $util->getXMLFromResult($model->get()); | ||
echo $dbutil->getXMLFromResult($query, $config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$dbutil = \Config\Database::utils(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$dbutil = \Config\Database::utils('group_name'); |