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

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

WBOY
WBOYOriginal
2016-07-29 09:04:14772browse

laravel artisan common commands:

Create controller:

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

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>

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>

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>

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

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

Session operation:

Store a variable:

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

Read a variable:

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

Read a variable or return the default value:

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

Check if a variable exists:

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

Delete a variable:

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

Delete all Session variables:

<code><span>Session</span><span>::flush</span>;</code>

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.

Statement:
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