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
3 changes: 2 additions & 1 deletion user_guide_src/source/tutorial/create_news_items.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ Most helper functions require the helper to be loaded before use.
Next, we check if we deal with the **POST** request with the
:doc:`IncomingRequest <../incoming/incomingrequest>` object ``$this->request``.
It is set in the controller by the framework.
If the HTTP method is not POST, that is it is GET,
The :ref:`IncomingRequest::is() <incomingrequest-is>` method checks the type of the request.
Since the route for **create()** endpoint handles both: **GET** and **POST** requests we can safely assume that if the request is not POST then it is a GET type.
the form is loaded and returned to display.

Then, we get the necessary items from the POST data by the user and set them in the ``$post`` variable.
Expand Down
6 changes: 3 additions & 3 deletions user_guide_src/source/tutorial/create_news_items/002.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function create()
helper('form');

// Checks whether the form is submitted.
if (strtolower($this->request->getMethod()) !== 'post') {
if (! $this->request->is('post')) {
// The form is not submitted, so returns the form.
return view('templates/header', ['title' => 'Create a news item'])
. view('news/create')
Expand All @@ -24,8 +24,8 @@ public function create()

// Checks whether the submitted data passed the validation rules.
if (! $this->validateData($post, [
'title' => 'required|min_length[3]|max_length[255]',
'body' => 'required|min_length[10]|max_length[5000]',
'title' => 'required|max_length[255]|min_length[3]',
'body' => 'required|max_length[5000]|min_length[10]',
Comment thread
michalsn marked this conversation as resolved.
])) {
// The validation fails, so returns the form.
return view('templates/header', ['title' => 'Create a news item'])
Expand Down