Home > Article > PHP Framework > [laravel] blog project practical notes - operations of creating a project and logging in
I always want to do a small project by myself, but I don’t know how to start. I always do a certain part of the project when I go to work, and I don’t do a project as a whole. The following is a summary of the videos I watched on the PHP Chinese website. Notes for your reference. This is a practical blog project done in a Windows environment.
1. Create the project
1) Switch to the project directory (I put all the projects in the code folder)
cd code
2) Create Project (the project name is blog)
composer create-project laravel/laravel blog --prefer-dist 指优先安装压缩版
2. Distribute routing and verification code references
1) First assign a route (each reference address must be assigned Routing)
After the creation is successful, check whether it can be successfully accessed
2) Reference the third-party library (under the resource folder, represented by org)
3) In the controller Load class require_once '../resources/org/code/Code.class.php';
session_start();
The laravel framework itself encapsulates the session. It is possible to use the native session when referencing the extension class. The entry file index.php enables the call of the
require_once '../resources/org/code/Code.class.php'; //先把类包含进来,实际路径根据实际情况进行修改。 $code = new Code(); //实例化一个对象 $code->doimg(); $_SESSION['code'] = $code->getCode();//验证码保存到SESSION中
image: use the routing access method
{{url('') }}
It is possible that the verification code is not clear:
This is when we add a click event to create a new verification code every time we clickalt="' onclick=" this.src='{{'home/code'}}'"
Some browsers will think that the address has not changed, so the verification code remains unchanged
alt="' onclick="this.src='{{'home/code'}}?'-Math.random()"
3. Login form submission CRFS authentication and verification code judgment
1) Note that when submitting the form, the submit button must be in ff9c23ada1bcecdd1a0fb5d5a0f18437
2) 419 error is laravel In the CRFS authentication question of the framework, write {{csrf_field()}} in the ff9c23ada1bcecdd1a0fb5d5a0f18437
3) The name in the input tag is the value to be passed to the background
4) Use Input:: all() takes the value passed from the front desk, which is equivalent to is_post. Use back to return to the previous page with the information stored in the session
if($input = Input::all()){ $code = new \Code; //实例化一个对象 $_code = $code->getCode(); //获取本身的验证码 if($input['code'] != $_code ){ return back()-> with('msg','验证码错误!'); }else{ dd(123); } }else{ return view('home/login'); }
5) Use the session to determine the value of the page prompt information
@if(session('msg')) <p style="color: #f30a28;font-size: 12px;text-align: center;">{{session('msg')}}</p> @endif
The above steps are my study notes. I wrote down the steps or key points to be operated. If you don’t understand anything, you can leave a message. Thank you for your support. I hope it can help newcomers. If you want to see more blog project information, Follow me and continue sharing in the next article.
Recommended learning: "laravel tutorial"
The above is the detailed content of [laravel] blog project practical notes - operations of creating a project and logging in. For more information, please follow other related articles on the PHP Chinese website!