Skip to content

Commit c875d33

Browse files
committed
docs: improve descriptions in Factories
1 parent 1a83ef4 commit c875d33

5 files changed

Lines changed: 20 additions & 18 deletions

File tree

user_guide_src/source/concepts/factories.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Factories
44

55
.. contents::
66
:local:
7-
:depth: 2
7+
:depth: 3
88

99
Introduction
1010
************
@@ -41,17 +41,14 @@ On the other hand, Services have code to create instances, so it can create a co
4141
that needs other services or class instances. When you get a service, Services require a service name,
4242
not a class name, so the returned instance can be changed without changing the client code.
4343

44+
.. _factories-loading-class:
45+
4446
Loading Classes
4547
***************
4648

4749
Loading a Class
4850
===============
4951

50-
.. _factories-example:
51-
52-
Model Example
53-
-------------
54-
5552
Take a look at **Models** as an example. You can access the Factory specific to Models
5653
by using the magic static method of the Factories class, ``Factories::models()``.
5754

@@ -64,7 +61,17 @@ In the following code, if you have ``App\Models\UserModel``, the instance will b
6461

6562
.. literalinclude:: factories/001.php
6663

67-
Or you could also request a specific class:
64+
If you don't have ``App\Models\UserModel``, it searches for ``Models\UserModel`` in all namespaces.
65+
66+
Next time you ask for the same class anywhere in your code, Factories will be sure
67+
you get back the instance as before:
68+
69+
.. literalinclude:: factories/003.php
70+
71+
preferApp option
72+
----------------
73+
74+
You could also request a specific class:
6875

6976
.. literalinclude:: factories/002.php
7077
:lines: 2-
@@ -78,13 +85,6 @@ If you want to get ``Blog\Models\UserModel``, you need to disable the option ``p
7885
.. literalinclude:: factories/010.php
7986
:lines: 2-
8087

81-
See :ref:`factories-options` for the details.
82-
83-
Next time you ask for the same class anywhere in your code, Factories will be sure
84-
you get back the instance as before:
85-
86-
.. literalinclude:: factories/003.php
87-
8888
Loading a Class in Sub-directories
8989
==================================
9090

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<?php
22

33
$users = Factories::models('Blog\Models\UserModel');
4+
// Or
5+
$users = Factories::models(\Blog\Models\UserModel::class);

user_guide_src/source/general/common_functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Service Accessors
110110
More simple way of getting model instances.
111111

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

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

user_guide_src/source/general/modules.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Config files are automatically discovered whenever using the ``config()`` functi
194194

195195
.. note:: ``config()`` finds the file in **app/Config/** when there is a class with the same shortname,
196196
even if you specify a fully qualified class name like ``config(\Acme\Blog\Config\Blog::class)``.
197-
This is because ``config()`` is a wrapper for the ``Factories`` class which uses ``preferApp`` by default. See :ref:`Factories Example <factories-example>` for more information.
197+
This is because ``config()`` is a wrapper for the ``Factories`` class which uses ``preferApp`` by default. See :ref:`factories-loading-class` for more information.
198198

199199
Migrations
200200
==========
@@ -250,7 +250,7 @@ Model files are automatically discovered whenever using the :php:func:`model()`
250250

251251
.. note:: ``model()`` finds the file in **app/Models/** when there is a class with the same shortname,
252252
even if you specify a fully qualified class name like ``model(\Acme\Blog\Model\PostModel::class)``.
253-
This is because ``model()`` is a wrapper for the ``Factories`` class which uses ``preferApp`` by default. See :ref:`Factories Example <factories-example>` for more information.
253+
This is because ``model()`` is a wrapper for the ``Factories`` class which uses ``preferApp`` by default. See :ref:`factories-loading-class` for more information.
254254

255255
Views
256256
=====

user_guide_src/source/models/model.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can access models within your classes by creating a new instance or using th
2929
.. literalinclude:: model/001.php
3030

3131
The ``model()`` uses ``Factories::models()`` internally.
32-
See :ref:`factories-example` for details on the first parameter.
32+
See :ref:`factories-loading-class` for details on the first parameter.
3333

3434
CodeIgniter's Model
3535
*******************

0 commit comments

Comments
 (0)