Skip to content

Commit 22906b3

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents 7aad65d + 36e555c commit 22906b3

File tree

24 files changed

+208
-113
lines changed

24 files changed

+208
-113
lines changed

system/Commands/Database/ShowTableInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ public function run(array $params)
127127
$limitRows = (int) ($params['limit-rows'] ?? 10);
128128
$limitFieldValue = (int) ($params['limit-field-value'] ?? 15);
129129

130-
if (! in_array($tableName, $tables, true)) {
130+
while (! in_array($tableName, $tables, true)) {
131131
$tableNameNo = CLI::promptByKey(
132132
['Here is the list of your database tables:', 'Which table do you want to see?'],
133133
$tables,
134134
'required'
135135
);
136136
CLI::newLine();
137137

138-
$tableName = $tables[$tableNameNo];
138+
$tableName = $tables[$tableNameNo] ?? null;
139139
}
140140

141141
if (array_key_exists('metadata', $params)) {

system/Commands/Utilities/Routes/SampleURIGenerator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use CodeIgniter\Config\Services;
1515
use CodeIgniter\Router\RouteCollection;
16+
use Config\App;
1617

1718
/**
1819
* Generate a sample URI path from route key regex.
@@ -51,6 +52,14 @@ public function get(string $routeKey): string
5152
{
5253
$sampleUri = $routeKey;
5354

55+
if (strpos($routeKey, '{locale}') !== false) {
56+
$sampleUri = str_replace(
57+
'{locale}',
58+
config(App::class)->defaultLocale,
59+
$routeKey
60+
);
61+
}
62+
5463
foreach ($this->routes->getPlaceholders() as $placeholder => $regex) {
5564
$sample = $this->samples[$placeholder] ?? '::unknown::';
5665

system/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Controller
6565
/**
6666
* Once validation has been run, will hold the Validation instance.
6767
*
68-
* @var ValidationInterface
68+
* @var ValidationInterface|null
6969
*/
7070
protected $validator;
7171

tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public static function provideGet(): iterable
4040
'placeholder num' => ['shop/product/([0-9]+)', 'shop/product/123'],
4141
'placeholder segment' => ['shop/product/([^/]+)', 'shop/product/abc_123'],
4242
'placeholder any' => ['shop/product/(.*)', 'shop/product/123/abc'],
43+
'locale' => ['{locale}/home', 'en/home'],
44+
'locale segment' => ['{locale}/product/([^/]+)', 'en/product/abc_123'],
4345
'auto route' => ['home/index[/...]', 'home/index/1/2/3/4/5'],
4446
];
4547
}

user_guide_src/source/incoming/controllers.rst

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,48 @@ modify this by passing the duration (in seconds) as the first parameter:
8787
Validating Data
8888
***************
8989

90+
.. _controller-validatedata:
91+
92+
$this->validateData()
93+
=====================
94+
95+
.. versionadded:: 4.2.0
96+
97+
To simplify data checking, the controller also provides the convenience method
98+
``validateData()``.
99+
100+
The method accepts (1) an array of data to validate, (2) an array of rules,
101+
(3) an optional array of custom error messages to display if the items are not valid,
102+
(4) an optional database group to use.
103+
104+
The :doc:`Validation Library docs </libraries/validation>` have details on
105+
rule and message array formats, as well as available rules:
106+
107+
.. literalinclude:: controllers/006.php
108+
90109
.. _controller-validate:
91110

92111
$this->validate()
93112
=================
94113

95-
To simplify data checking, the controller also provides the convenience method ``validate()``.
114+
.. important:: This method exists only for backward compatibility. Do not use it
115+
in new projects. Even if you are already using it, we recommend that you use
116+
the ``validateData()`` method instead.
117+
118+
The controller also provides the convenience method ``validate()``.
119+
120+
.. warning:: Instead of ``validate()``, use ``validateData()`` to validate POST
121+
data only. ``validate()`` uses ``$request->getVar()`` which returns
122+
``$_GET``, ``$_POST`` or ``$_COOKIE`` data in that order (depending on php.ini
123+
`request-order <https://www.php.net/manual/en/ini.core.php#ini.request-order>`_).
124+
Newer values override older values. POST values may be overridden by the
125+
cookies if they have the same name.
126+
96127
The method accepts an array of rules in the first parameter,
97128
and in the optional second parameter, an array of custom error messages to display
98-
if the items are not valid. Internally, this uses the controller's
129+
if the items are not valid.
130+
131+
Internally, this uses the controller's
99132
``$this->request`` instance to get the data to be validated.
100133

101134
The :doc:`Validation Library docs </libraries/validation>` have details on
@@ -123,19 +156,6 @@ the ``$rules`` array with the name of the group as defined in **app/Config/Valid
123156

124157
.. note:: Validation can also be handled automatically in the model, but sometimes it's easier to do it in the controller. Where is up to you.
125158

126-
.. _controller-validatedata:
127-
128-
$this->validateData()
129-
=====================
130-
131-
.. versionadded:: 4.2.0
132-
133-
Sometimes you may want to check the controller method parameters or other custom data.
134-
In that case, you can use the ``$this->validateData()`` method.
135-
The method accepts an array of data to validate in the first parameter:
136-
137-
.. literalinclude:: controllers/006.php
138-
139159
Protecting Methods
140160
******************
141161

user_guide_src/source/incoming/controllers/006.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public function product(int $id)
88
{
99
$data = [
1010
'id' => $id,
11-
'name' => $this->request->getVar('name'),
11+
'name' => $this->request->getPost('name'),
1212
];
1313

1414
$rule = [

0 commit comments

Comments
 (0)