Introduction to the top PHP framework Laravel (1) Laravel-a master-level framework, making code an art

Source: Internet
Author: User
: This article mainly introduces Laravel, a top-level PHP Framework. (1) Laravel, a master-level framework, helps code become an art. if you are interested in PHP tutorials, refer to it. Common commands for laravel artisan:

Create a controller:

php artisan make:controller Front/Users/UsersController

Automatically created
./App/Http/Controllers/Front/Users/UsersController. php file

Common function code

1 Redirection

return Redirect('user/login');    

2 session and cookie

Laravel uses file by default to implement session. She does not use php native$_SESSION(Php native session depends on the position of php. ini), so ignore php-related session functions, such as session_start (), $ _ SESSION. Laravel will write session information in the app/storage/session/directory during running. Therefore, this directory requires write permission. Otherwise, the session cannot be written successfully.

Cookie operation:

Obtain the value in the Cookie:

Cookie::get('name');

Add a Cookie:

$response= Response::make('Hello World');response?>withCookie(Cookie::make(′name′,′value′,minutes));

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

Cookie::queue(name,value, $minute);

Session operation:

Store a variable:

Session::put('key', 'value');

Read a variable:

Session::get('key');

Read a variable or return the default value:

Session::get('key', 'default');

Check whether a variable exists:

Sesssion::has('key');

Delete a variable:

Session::forget('key');

Delete all Session variables:

Session::flush;

Differences between cookie and session:

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

2. cookies are not safe. others can analyze the cookies stored locally and perform cookie spoofing.
Session should be used for security consideration.

3. the session will be stored on the server for a certain period of time. When the number of accesses increases, it will occupy the performance of your server.
COOKIE should be used in consideration of reducing server performance.

4. data stored in a single cookie cannot exceed 4 kB. many browsers limit that a site can store up to 20 cookies.

5. personal suggestions:
Store important information such as login information as SESSION
Other information can be stored in the COOKIE if it needs to be retained.

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces Laravel, a top-level PHP Framework. (1) I first learned Laravel, a master-level framework, and made code an art, if you are interested in PHP tutorials.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.