Introduction to the top PHP framework Laravel (1) First introduction to Laravel - a master-level framework that turns code into art

WBOY
Release: 2016-07-29 09:04:14
Original
771 people have browsed it

laravel artisan common commands:

Create controller:

<code>php artisan make:controller <span>Front</span>/Users/UsersController</code>
Copy after login

will be created automatically
./app/Http/Controllers/Front/Users/UsersController.php file

Common function codes

1 Redirect

<code><span>return</span> Redirect(<span>'user/login'</span>);    </code>
Copy after login

2 Session and cookie

Laravel uses file by default to implement session. She does not use PHP's native $_SESSION (php's native session depends on the location of php.ini), so she ignores PHP-related session functions, such as session_start(), $_SESSION. During the running process, Laravel will write session information in the app/storage/session/ directory, so this directory needs to have write permission, otherwise the session will not be written successfully.

Cookie operation:

Get the value in the cookie:

<code>Cookie::<span>get</span>(<span>'name'</span>);</code>
Copy after login

Add a cookie:

<code><span>$response</span><span>=</span> Response<span>::make</span>(<span>'Hello World'</span>);

response?<span>></span>withCookie(Cookie<span>::make</span>(′name′,′value′,minutes));</code>
Copy after login

If you want to set a cookie before Response, use Cookie::queue()

<code>Cookie<span>::queue</span>(name,value, <span>$minute</span>);</code>
Copy after login

Session operation:

Store a variable:

<code>Session<span>::put(<span>'key'</span>, <span>'value'</span>);</span></code>
Copy after login

Read a variable:

<code>Session::<span>get</span>(<span>'key'</span>);</code>
Copy after login

Read a variable or return the default value:

<code>Session::<span>get</span>(<span>'key'</span>, <span>'default'</span>);</code>
Copy after login

Check if a variable exists:

<code>Sesssion::<span>has</span>(<span>'key'</span>);</code>
Copy after login

Delete a variable:

<code>Session<span>::forget(<span>'key'</span>);</span></code>
Copy after login

Delete all Session variables:

<code><span>Session</span><span>::flush</span>;</code>
Copy after login

Cookie and session The difference:

1. The cookie data is stored on the client's browser, and the session data is stored on the server.

2. Cookies are not very safe. Others can analyze the cookies stored locally and deceive them.
Session should be used for security reasons.

3. The session will be saved on the server for a certain period of time. When access increases, it will take up more of your server’s performance
Taking into account the reduction of server performance, COOKIE should be used.

4. The data saved by a single cookie cannot exceed 4K. Many browsers limit a site to save up to 20 cookies.

5. So personal suggestions:
Store important information such as login information as SESSION
If other information needs to be retained, it can be placed in COOKIE

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the introduction of the top PHP framework Laravel (1) First introduction to Laravel - a master-level framework that makes code become art, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template