Requests
Handling HTTP Requests
Accessing The Request
To obtain an instance of the current HTTP request, you should use the request
helper method:
Using request()
without passing any arguments will return the current request instance.
Request Parameters & Method
Retrieving Method
The method
method returns the request method:
Retrieving parameter
The params
method returns the request/server parameter with the given key or returns all the request/server parameters if there's no key:
Retrieving Inputs
If you want to get all request input:
If you want to get an input value:
or
You may pass a default value as the second argument to the input method. This value will be returned if the requested input value is not present on the request:
Retrieving Portion Of The Input Data
If you need to retrieve a subset of the input data, you may use the only
and except
methods. Both of these methods accept a single array or a dynamic list of arguments:
Flash
The flash
method will flash a message to the current session so that it is available during the user next request:
Retrieving Cookie From Request
All cookies created by the Atom framework are encrypted and signed with an authentication code, meaning they will be considered invalid if they have been changed by the client. To retrieve a cookie value from the request, use the cookie
method on a request instance:
Files
Retrieving Uploaded Files
You may access uploaded files from a Atom\Request\Request
instance using the files
method or file
method. The file
method returns an instance of the Atom\Request\UploadedFile
class, which provides a variety of methods for interacting with the file:
File Properties
The UploadedFile
class also contains the get
method for accessing the file properties. For example:
Here is a list of all file properties:
Property
Description
name
Name of the uploaded file
type
Type of the uploaded file
size
Size of the uploaded file
extension
Extension of the uploaded file
tmp_name
Temporary path to the uploaded file
real_path
Path to the file uploaded on your server
real_name
Name of the file uploaded on your server
Storing Uploaded Files
To store an uploaded file, you will typically use one of your configured storage
. The UploadedFile
class has a store
and storeAs
method which will move an uploaded file to one of your disks, which may be a location on your local filesystem.
The store
method accepts an optionalpublic
argument which determine if the file should be publicly accessible and an second optional serialize
argument which determine if the file contents should be serialized. By default, the file is not publicly accessible and the contents of the file will not be serialized:
A unique ID will automatically be generated to serve as the file The method will return the uploaded file or false if file wasn't uploaded:
If you do not want a file name to be automatically generated, you may use the storeAs
method, which accepts the file name, public storage, and serialization as its arguments:
Dernière mise à jour
Cet article vous a-t-il été utile ?