Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion user_guide_src/source/general/common_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ Service Accessors
:param string $name: The model classname.
:param boolean $getShared: Whether to return a shared instance.
:param ConnectionInterface|null $conn: The database connection.
:returns: More simple way of getting model instances
:returns: The model instances
:rtype: object

More simple way of getting model instances.

The ``model()`` uses ``Factories::models()`` internally.
See :ref:`factories-example` for details on the first parameter ``$name``.

See also the :ref:`Using CodeIgniter's Model <accessing-models>`.

.. php:function:: old($key[, $default = null,[, $escape = 'html']])
Expand Down
5 changes: 4 additions & 1 deletion user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ updating records, deleting records, and more.
Accessing Models
****************

Models are typically stored in the ``app/Models`` directory. They should have a namespace that matches their
Models are typically stored in the **app/Models** directory. They should have a namespace that matches their
location within the directory, like ``namespace App\Models``.

You can access models within your classes by creating a new instance or using the :php:func:`model()` helper function.

.. literalinclude:: model/001.php

The ``model()`` uses ``Factories::models()`` internally.
See :ref:`factories-example` for details on the first parameter.

CodeIgniter's Model
*******************

Expand Down
12 changes: 7 additions & 5 deletions user_guide_src/source/models/model/001.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
// Create a new class manually.
$userModel = new \App\Models\UserModel();

// Create a new class with the model() function.
$userModel = model('App\Models\UserModel', false);

// Create a shared instance of the model.
$userModel = model('UserModel');
// or
$userModel = model('App\Models\UserModel');
// or
$userModel = model(App\Models\UserModel::class);

// Create a new class with the model() function.
$userModel = model('UserModel', false);

// Create shared instance with a supplied database connection.
// When no namespace is given, it will search through all namespaces
// the system knows about and attempts to locate the UserModel class.
$db = db_connect('custom');
$userModel = model('UserModel', true, $db);