Skip to content

Commit 2923328

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.4
2 parents 8ab4a58 + d26b65e commit 2923328

File tree

8 files changed

+81
-24
lines changed

8 files changed

+81
-24
lines changed

user_guide_src/source/concepts/autoloader.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,26 @@ Namespaces
4747

4848
The recommended method for organizing your classes is to create one or more namespaces for your
4949
application's files. This is most important for any business-logic related classes, entity classes,
50-
etc. The ``psr4`` array in the configuration file allows you to map the namespace to the directory
50+
etc. The ``$psr4`` array in the configuration file allows you to map the namespace to the directory
5151
those classes can be found in:
5252

5353
.. literalinclude:: autoloader/001.php
5454

5555
The key of each row is the namespace itself. This does not need a trailing back slash.
56-
The value is the location to the directory the classes can be found in. They should
57-
have a trailing slash.
56+
The value is the location to the directory the classes can be found in.
5857

5958
.. note:: You can check the namespace configuration by ``spark namespaces`` command::
6059

6160
> php spark namespaces
6261

63-
By default, the application folder is namespace to the ``App`` namespace. While you are not forced to namespace the controllers,
64-
libraries, or models in the application directory, if you do, they will be found under the ``App`` namespace.
62+
By default, the application directory is namespace to the ``App`` namespace. You must namespace the controllers,
63+
libraries, or models in the application directory, and they will be found under the ``App`` namespace.
64+
6565
You may change this namespace by editing the **app/Config/Constants.php** file and setting the
6666
new namespace value under the ``APP_NAMESPACE`` setting:
6767

6868
.. literalinclude:: autoloader/002.php
69+
:lines: 2-
6970

7071
You will need to modify any existing files that are referencing the current namespace.
7172

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<?php
22

3-
$psr4 = [
4-
'App' => APPPATH,
5-
'CodeIgniter' => SYSTEMPATH,
6-
];
3+
namespace Config;
4+
5+
use CodeIgniter\Config\AutoloadConfig;
6+
7+
class Autoload extends AutoloadConfig
8+
{
9+
// ...
10+
public $psr4 = [
11+
APP_NAMESPACE => APPPATH, // For custom app namespace
12+
'Config' => APPPATH . 'Config',
13+
];
14+
15+
// ...
16+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
define('APP_NAMESPACE', 'App');
3+
defined('APP_NAMESPACE') || define('APP_NAMESPACE', 'App');
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?php
22

3-
$classmap = [
4-
'Markdown' => APPPATH . 'third_party/markdown.php',
5-
];
3+
namespace Config;
4+
5+
use CodeIgniter\Config\AutoloadConfig;
6+
7+
class Autoload extends AutoloadConfig
8+
{
9+
// ...
10+
public $classmap = [
11+
'Markdown' => APPPATH . 'ThirdParty/markdown.php',
12+
];
13+
14+
// ...
15+
}

user_guide_src/source/helpers/form_helper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ The following functions are available:
534534
that are stored in the session. To store the errors in the session, you need to use ``withInput()`` with :php:func:`redirect() <redirect>`.
535535

536536
The returned array is the same as ``Validation::getErrors()``.
537-
See :ref:`Validation <validation-getting-all-errors>` for details.
537+
See :ref:`Validation <validation-redirect-and-validation-errors>` for details.
538538

539539
Example::
540540

user_guide_src/source/incoming/methodspoofing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
====================
1+
####################
22
HTTP Method Spoofing
3-
====================
3+
####################
44

55
When working with HTML forms you can only use GET or POST HTTP verbs. In most cases, this is just fine. However, to
66
support REST-ful routing you need to support other, more correct, verbs, like DELETE or PUT. Since the browsers
@@ -11,7 +11,7 @@ To spoof the method, a hidden input is added to the form with the name of ``_met
1111
that you want the request to be::
1212

1313
<form action="" method="post">
14-
<input type="hidden" name="_method" value="PUT" />
14+
<input type="hidden" name="_method" value="PUT">
1515
</form>
1616

1717
This form is converted into a PUT request and is a true PUT request as far as the routing and the IncomingRequest

user_guide_src/source/libraries/validation.rst

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.. _validation:
22

3+
##########
34
Validation
45
##########
56

@@ -10,6 +11,7 @@ helps minimize the amount of code you'll write.
1011
:local:
1112
:depth: 2
1213

14+
********
1315
Overview
1416
********
1517

@@ -42,6 +44,7 @@ messages, various control structures are usually placed within the form
4244
HTML. Form validation, while simple to create, is generally very messy
4345
and tedious to implement.
4446

47+
************************
4548
Form Validation Tutorial
4649
************************
4750

@@ -197,6 +200,7 @@ Then add validation rules in the controller (**Form.php**):
197200

198201
If you submit the form you should see the success page or the form with error messages.
199202

203+
*********************
200204
Config for Validation
201205
*********************
202206

@@ -238,6 +242,7 @@ If you want to use traditional rules, you need to change the rule classes in **a
238242

239243
.. literalinclude:: validation/003.php
240244

245+
*******************
241246
Loading the Library
242247
*******************
243248

@@ -251,6 +256,7 @@ for including multiple Rulesets, and collections of rules that can be easily reu
251256
.. note:: You may never need to use this method, as both the :doc:`Controller </incoming/controllers>` and
252257
the :doc:`Model </models/model>` provide methods to make validation even easier.
253258

259+
************************
254260
Setting Validation Rules
255261
************************
256262

@@ -311,6 +317,7 @@ data to be validated:
311317
is not HTML form post (``Content-Type: multipart/form-data``),
312318
or gets data from :ref:`$request->getVar() <incomingrequest-getting-data>`.
313319

320+
***********************
314321
Working with Validation
315322
***********************
316323

@@ -426,13 +433,14 @@ So it will ignore the row in the database that has ``id=4`` when it verifies the
426433
This can also be used to create more dynamic rules at runtime, as long as you take care that any dynamic
427434
keys passed in don't conflict with your form data.
428435

429-
Working With Errors
436+
*******************
437+
Working with Errors
430438
*******************
431439

432440
The Validation library provides several methods to help you set error messages, provide
433441
custom error messages, and retrieve one or more errors to display.
434442

435-
By default, error messages are derived from language strings in ``system/Language/en/Validation.php``, where
443+
By default, error messages are derived from language strings in **system/Language/en/Validation.php**, where
436444
each rule has an entry.
437445

438446
.. _validation-custom-errors:
@@ -467,11 +475,11 @@ at least 6 characters."
467475

468476
.. note:: When using label-style error messages, if you pass the second parameter to ``setRules()``, it will be overwritten with the value of the first parameter.
469477

470-
Translation Of Messages And Validation Labels
478+
Translation of Messages and Validation Labels
471479
=============================================
472480

473481
To use translated strings from language files, we can simply use the dot syntax.
474-
Let's say we have a file with translations located here: ``app/Languages/en/Rules.php``.
482+
Let's say we have a file with translations located here: **app/Languages/en/Rules.php**.
475483
We can simply use the language lines defined in this file, like this:
476484

477485
.. literalinclude:: validation/025.php
@@ -530,8 +538,28 @@ When specifying a field with a wildcard, all errors matching the mask will be ch
530538

531539
.. literalinclude:: validation/029.php
532540

541+
.. _validation-redirect-and-validation-errors:
542+
543+
Redirect and Validation Errors
544+
==============================
545+
546+
PHP shares nothing between requests. So when you redirect if a validation fails,
547+
there will be no validation errors in the redirected request because the validation
548+
has run in the previous request.
549+
550+
In that case, you need to use Form helper function :php:func:`validation_errors()`,
551+
:php:func:`validation_list_errors()` and :php:func:`validation_show_error()`.
552+
These functions check the validation errors that are stored in the session.
553+
554+
To store the validation errors in the session, you need to use ``withInput()``
555+
with :php:func:`redirect() <redirect>`:
556+
557+
.. literalinclude:: validation/042.php
558+
:lines: 2-
559+
533560
.. _validation-customizing-error-display:
534561

562+
*************************
535563
Customizing Error Display
536564
*************************
537565

@@ -562,7 +590,7 @@ error message. This is used with the ``showError()`` method where a field must b
562590
Configuration
563591
=============
564592

565-
Once you have your views created, you need to let the Validation library know about them. Open ``Config/Validation.php``.
593+
Once you have your views created, you need to let the Validation library know about them. Open **app/Config/Validation.php**.
566594
Inside, you'll find the ``$templates`` property where you can list as many custom views as you want, and provide an
567595
short alias they can be referenced by. If we were to add our example file from above, it would look something like:
568596

@@ -580,6 +608,7 @@ right after the name of the field the error should belong to::
580608

581609
<?= $validation->showError('username', 'my_single') ?>
582610

611+
*********************
583612
Creating Custom Rules
584613
*********************
585614

@@ -592,7 +621,7 @@ autoloader can find it. These files are called RuleSets.
592621
Adding a RuleSet
593622
----------------
594623

595-
To add a new RuleSet, edit **Config/Validation.php** and
624+
To add a new RuleSet, edit **app/Config/Validation.php** and
596625
add the new file to the ``$ruleSets`` array:
597626

598627
.. literalinclude:: validation/033.php
@@ -608,7 +637,7 @@ a boolean true or false value signifying true if it passed the test or false if
608637

609638
.. literalinclude:: validation/034.php
610639

611-
By default, the system will look within ``CodeIgniter\Language\en\Validation.php`` for the language strings used
640+
By default, the system will look within **system/Language/en/Validation.php** for the language strings used
612641
within errors. In custom rules, you may provide error messages by accepting a ``&$error`` variable by reference in the
613642
second parameter:
614643

@@ -654,6 +683,7 @@ Or you can use the following parameters:
654683

655684
.. literalinclude:: validation/041.php
656685

686+
***************
657687
Available Rules
658688
***************
659689

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
// In Controller.
4+
if (! $this->validateData($data, $rules)) {
5+
return redirect()->back()->withInput();
6+
}

0 commit comments

Comments
 (0)