Skip to content

Commit

Permalink
Merge pull request #2903 from codeigniter4/ugtweaks
Browse files Browse the repository at this point in the history
Ugtweaks
  • Loading branch information
lonnieezell committed Apr 29, 2020
2 parents d49e6ac + 06cdc12 commit 06dd676
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 141 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,11 @@ If you are using the command-line, you can do the following to update your fork
3. `git push origin develop`

Your fork is now up to date. This should be done regularly and, at the least, before you submit a pull request.

## Translations Installation

If you wish to contribute to the system message translations,
then fork and clone the [translations repository](https://github.com/codeigniter4/translations>)
separately from the codebase.

These are two independent repositories!
10 changes: 7 additions & 3 deletions user_guide_src/source/concepts/http.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ is an object-oriented representation of the HTTP request. It provides everything

use CodeIgniter\HTTP\IncomingRequest;

$request = new IncomingRequest(new \Config\App(), new \CodeIgniter\HTTP\URI());
$request = service('request');

// the URI being requested (i.e. /about)
$request->uri->getPath();

// Retrieve $_GET and $_POST variables
$request->getVar('foo');
$request->getGet('foo');
$request->getPost('foo');

// Retrieve from $_REQUEST which should include
// both $_GET and $_POST contents
$request->getVar('foo');

// Retrieve JSON from AJAX calls
$request->getJSON();

Expand All @@ -104,14 +107,15 @@ of the HTTP response. This gives you an easy and powerful way to construct your

use CodeIgniter\HTTP\Response;

$response = new Response();
$response = service('response');

$response->setStatusCode(Response::HTTP_OK);
$response->setBody($output);
$response->setHeader('Content-type', 'text/html');
$response->noCache();

// Sends the output to the browser
// This is typically handled by the framework
$response->send();

In addition, the Response class allows you to work the HTTP cache layer for the best performance.
2 changes: 1 addition & 1 deletion user_guide_src/source/concepts/services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Services
Introduction
============

All of the classes within CodeIgniter are provided as "services". This simply means that, instead
All of the core classes within CodeIgniter are provided as "services". This simply means that, instead
of hard-coding a class name to load, the classes to call are defined within a very simple
configuration file. This file acts as a type of factory to create new instances of the required class.

Expand Down
86 changes: 43 additions & 43 deletions user_guide_src/source/general/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Configuration
#############

Every framework uses configuration files to define numerous parameters and
initial settings. CodeIgniter configuration files define simple classes where
the required settings are public properties.
Every framework uses configuration files to define numerous parameters and
initial settings. CodeIgniter configuration files define simple classes where
the required settings are public properties.

Unlike many other frameworks, CodeIgniter configurable items aren't contained in
a single file. Instead, each class that needs configurable items will have a
configuration file with the same name as the class that uses it. You will find
Unlike many other frameworks, CodeIgniter configurable items aren't contained in
a single file. Instead, each class that needs configurable items will have a
configuration file with the same name as the class that uses it. You will find
the application configuration files in the **/app/Config** folder.

.. contents::
Expand All @@ -21,45 +21,45 @@ Working With Configuration Files
You can access configuration files for your classes in several different ways.

- By using the ``new`` keyword to create an instance::

// Creating new configuration object by hand
$config = new \Config\Pager();

- By using the ``config()`` function::

// Creating a new object with config function
$config = config('Pager', false);

// Get shared instance with config function
$config = config('Pager');

// Access config class with namespace
$config = config( 'Config\\Pager' );

// Creating a new object with config function
$config = config('Pager', false);

All configuration object properties are public, so you access the settings like any other property::

$config = config('Pager');
// Access settings as object properties
$pageSize = $config->perPage;

If no namespace is provided, it will look for the file in all defined namespaces
as well as **/app/Config/**.
If no namespace is provided, it will look for the file in all defined namespaces
as well as **/app/Config/**.

All of the configuration files that ship with CodeIgniter are namespaced with
``Config``. Using this namespace in your application will provide the best
All of the configuration files that ship with CodeIgniter are namespaced with
``Config``. Using this namespace in your application will provide the best
performance since it knows exactly where to find the files.

You can put configuration files in any folder you want by using a different namespace.
This allows you to put configuration files on the production server in a folder
that is not web-accessible while keeping it under **/app** for easy access
You can put configuration files in any folder you want by using a different namespace.
This allows you to put configuration files on the production server in a folder
that is not web-accessible while keeping it under **/app** for easy access
during development.

Creating Configuration Files
============================

When you need a new configuration, first you create a new file at your desired location.
The default file location (recommended for most cases) is **/app/Config**.
The class should use the appropriate namespace, and it should extend
When you need a new configuration, first you create a new file at your desired location.
The default file location (recommended for most cases) is **/app/Config**.
The class should use the appropriate namespace, and it should extend
``CodeIgniter\Config\BaseConfig`` to ensure that it can receive environment-specific settings.

Define the class and fill it with public properties that represent your settings.::
Expand Down Expand Up @@ -87,11 +87,11 @@ Environment Variables and CodeIgniter

CodeIgniter makes it simple and painless to set Environment Variables by using a “dotenv” file. The term comes from the file name, which starts with a dot before the text “env”.

CodeIgniter expects **.env** to be at the root of your project alongside the ``system``
and ``app`` directories. There is a template file distributed with CodeIgniter that’s
located at the project root named **env** (Notice there’s no dot (**.**) at the start?).
It has a large collection of variables your project might use that have been assigned
empty, dummy, or default values. You can use this file as a starting place for your
CodeIgniter expects **.env** to be at the root of your project alongside the ``system``
and ``app`` directories. There is a template file distributed with CodeIgniter that’s
located at the project root named **env** (Notice there’s no dot (**.**) at the start?).
It has a large collection of variables your project might use that have been assigned
empty, dummy, or default values. You can use this file as a starting place for your
application by either renaming the template to **.env**, or by making a copy of it named **.env**.

.. important:: Make sure the **.env** file is NOT tracked by your version control system. For *git* that means adding it to **.gitignore**. Failure to do so could result in sensitive credentials being exposed to the public.
Expand All @@ -103,10 +103,10 @@ Settings are stored in **.env** files as a simple a collection of name/value pai
SECRET_KEY = super_secret_key
CI_ENVIRONMENT = development

When your application runs, **.env** will be loaded automatically, and the variables put
into the environment. If a variable already exists in the environment, it will NOT be
overwritten. The loaded Environment variables are accessed using any of the following:
``getenv()``, ``$_SERVER``, or ``$_ENV``.
When your application runs, **.env** will be loaded automatically, and the variables put
into the environment. If a variable already exists in the environment, it will NOT be
overwritten. The loaded Environment variables are accessed using any of the following:
``getenv()``, ``$_SERVER``, or ``$_ENV``.
::

$s3_bucket = getenv('S3_BUCKET');
Expand All @@ -127,8 +127,8 @@ variable name within ``${...}``
Namespaced Variables
====================

There will be times when you will have several variables with the same name.
The system needs a way of knowing what the correct setting should be.
There will be times when you will have several variables with the same name.
The system needs a way of knowing what the correct setting should be.
This problem is solved by "*namespacing*" the variables.

Namespaced variables use a dot notation to qualify variable names so they will be unique
Expand All @@ -153,27 +153,27 @@ Configuration Classes and Environment Variables
When you instantiate a configuration class, any *namespaced* environment variables
are considered for merging into the configuration object's properties.

If the prefix of a namespaced variable exactly matches the namespace of the configuration
class, then the trailing part of the setting (after the dot) is treated as a configuration
property. If it matches an existing configuration property, the environment variable's
value will replace the corresponding value from the configuration file. If there is no match,
the configuration class properties are left unchanged. In this usage, the prefix must be
the full (case-sensitive) namespace of the class.
If the prefix of a namespaced variable exactly matches the namespace of the configuration
class, then the trailing part of the setting (after the dot) is treated as a configuration
property. If it matches an existing configuration property, the environment variable's
value will replace the corresponding value from the configuration file. If there is no match,
the configuration class properties are left unchanged. In this usage, the prefix must be
the full (case-sensitive) namespace of the class.
::

Config\App.CSRFProtection = true
Config\App.CSRFProtection = true
Config\App.CSRFCookieName = csrf_cookie
Config\App.CSPEnabled = true


.. note:: Both the namespace prefix and the property name are case-sensitive. They must exactly match the full namespace and property names as defined in the configuration class file.

The same holds for a *short prefix*, which is a namespace using only the lowercase version of
the configuration class name. If the short prefix matches the class name,
The same holds for a *short prefix*, which is a namespace using only the lowercase version of
the configuration class name. If the short prefix matches the class name,
the value from **.env** replaces the configuration file value.
::

app.CSRFProtection = true
app.CSRFProtection = true
app.CSRFCookieName = csrf_cookie
app.CSPEnabled = true

Expand Down Expand Up @@ -216,9 +216,9 @@ Handling Different Environments

Configuring multiple environments is easily accomplished by using a separate **.env** file with values modified to meet that environment's needs.

The file should not contain every possible setting for every configuration class used by the application. In truth, it should include only those items that are specific to the environment or are sensitive details like passwords and API keys and other information that should not be exposed. But anything that changes between deployments is fair-game.
The file should not contain every possible setting for every configuration class used by the application. In truth, it should include only those items that are specific to the environment or are sensitive details like passwords and API keys and other information that should not be exposed. But anything that changes between deployments is fair-game.

In each environment, place the **.env** file in the project's root folder. For most setups, this will be the same level as the ``system`` and ``app`` directories.
In each environment, place the **.env** file in the project's root folder. For most setups, this will be the same level as the ``system`` and ``app`` directories.

Do not track **.env** files with your version control system. If you do, and the repository is made public, you will have put sensitive information where everybody can find it.

Expand Down
11 changes: 4 additions & 7 deletions user_guide_src/source/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,25 @@ Installation

CodeIgniter4 can be installed in a number of different ways: manually,
using `Composer <https://getcomposer.org>`_, or using
`Git <https://git-scm.com/>`_.
`Git <https://git-scm.com/>`_.
Which is right for you?

- If you would like the simple "download & go" install that CodeIgniter3
is known for, choose the manual installation.
- If you plan to add third party packages to your project, we
recommend the Composer installation.
- If you are thinking of contributing to the framework,
then the Git installation is right for you.
- If you plan to add third party packages to your project, or want to keep
CodeIgniter up to date easily, we recommend the Composer installation.

.. toctree::
:titlesonly:

installing_manual
installing_composer
installing_git
running
upgrading
troubleshooting
repositories

However you choose to install and run CodeIgniter4, the
However you choose to install and run CodeIgniter4, the
`user guide <https://codeigniter4.github.io/userguide/>`_ is accessible online.

.. note:: Before using CodeIgniter 4, make sure that your server meets the
Expand Down
79 changes: 0 additions & 79 deletions user_guide_src/source/installation/installing_git.rst

This file was deleted.

2 changes: 1 addition & 1 deletion user_guide_src/source/installation/repositories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ but which showcase it or make it easier to work with!
+==================+==============+=================================================================+
| website2 | developers | The codeigniter.com website, written in CodeIgniter 4 |
+------------------+--------------+-----------------------------------------------------------------+
| | | |
| playground | developers | Basic code examples in project form. Still growing. |
+------------------+--------------+-----------------------------------------------------------------+

These are not composer-installable repositories.
4 changes: 2 additions & 2 deletions user_guide_src/source/intro/credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ In 2014, CodeIgniter was acquired by the `British Columbia Institute of Technolo
<https://www.bcit.ca/>`_ and was then officially announced as a community-maintained
project.

Bleeding edge development is spearheaded by the handpicked contributors
of the CodeIgniter Council.
In 2019, the CodeIgniter Foundation was formed to provide a perpetual managing group
separate from any other entity to help ensure the framework's future.
12 changes: 7 additions & 5 deletions user_guide_src/source/tutorial/create_news_items.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ the slug from our title in the model. Create a new view at

<?= \Config\Services::validation()->listErrors(); ?>

<form action="/news/create">
<form action="/news/create" method="post">
<?= csrf_field() ?>

<label for="title">Title</label>
<input type="input" name="title" /><br />
Expand All @@ -33,9 +34,10 @@ the slug from our title in the model. Create a new view at

</form>

There is only one thing here that probably look unfamiliar to you: the
``\Config\Services::validation()->listErrors()`` function. It is used to report
errors related to form validation.
There are probably only two things here that look unfamiliar. The
``\Config\Services::validation()->listErrors()`` function is used to report
errors related to form validation. The ``csrf_field()`` function creates
a hidden input with a CSRF token that helps protect against some common attacks.

Go back to your ``News`` controller. You're going to do two things here,
check whether the form was submitted and whether the submitted data
Expand Down Expand Up @@ -169,4 +171,4 @@ with all of the files that you created in green.
The two modified configuration files (Database & Routes) are not shown.

.. image:: ../images/tutorial9.png
:align: left
:align: left
Loading

0 comments on commit 06dd676

Please sign in to comment.