Laravel Framework Detailed

Source: Internet
Author: User
Tags file upload php file php source code table name tmp folder


Composer installation

Laravel uses composer to manage dependencies, so make sure the composer is already installed on the machine before using Laravel.

First, install the Lavarel installer via composer.

In the Windows environment, open cmd and enter the following command line: Composer Create-project laravel/laravel--prefer-dist my_laravel (get name for installation file)

An error may be reported during the installation

This time, do not be afraid, just because your network is not good, can not download the content to the file, and so on when the network is good, then download it.

After the installation is complete, go to the page and open the laravel/public/index.php "portal file", and when the Laravel is displayed, the installation is successful, we can use it normally.

"Outreach: Composer is a tool for PHP management dependencies"

Simple to use

The following is a simple message board to explain

Configure the database First

The location of our configuration files in the Lavarel framework is in the. env file, ". Env is an environment profile"


Here we can complete the database configuration, then the table data operation

New Page "page location: Resources/views directory"

In the Laravel framework, as with the TP,YII framework, a controller corresponds to a folder of the same name, the view is placed under a folder, but the name of the view changes, "Easy point: The end of the file must end with. blade.php", on the page we can use the native code

New Controller "Controller location: App/http/controller"

The page in the controller displays "Return view (' page name ')"

Display the page, configure the route, configure it in the routes.php file

Routing: Macro send and limit requests

Common types of routes:

Any: For operations that are not particularly sensitive

Post: Sending data to the server

Get: Require server to transmit data down

Route-Pass parameters

Route::any (' method/{argument} ', Controller @ method)

We only have to configure the route so that the page can be displayed.

Simple operation in the controller

get and post connection values

We can use the simple method for the moment, in fact, we use our $_post and $_get, but this kind of connection value is not safe, so we used another method of connection value

Reference class: User Llluminate \support\facades/input;

Get a user-submitted value "code: $name =input::get (' name ')"

Determines whether the specified commit information exists

if (Input::has (' name ')) {

}

Get all user-submitted information

$input =input::all ();

Change and delete

User DB;

And then, in the search for additional deletions,

Increase

$res =db::table (' table name ')->insert (add content);

if ($res) {

Jump page

Return Redirect ()->action (' controller @ method ');

}

By deleting

$id =input::get (' id ') received the ID value passed over

$del =db::d elete (' Delete from table name where id=? ', [$id]);

Change

The ID of the content to be modified and the content after the modification is completed,

$UPD =db::table (' table name ')->where (' id ', $data [' id '])->update (modify content);

Check

$info =db::select (' select * from table name ');

Render data to a page

Return view (' page ', [' info ' = + $info]);

Simple operation of the view

Render the data transmitted by the Controller as shown in the figure.


In the view layer, we jump to the method, "{{URL ('/add ')}}, jump to add page"

Here is a brief introduction to the use of the session

To use the session, you must first call the session class in the controller and then open it.

<?php

Use session; Introduce session class

session start;//Open session

$_session[' Session name ']= a value;//value is stored in session

$_session[' Session name ')//So we can take the value of the session

$_session[' Session name ']=null//The session is stored as NULL, and the session can be destroyed.

?>

Let's take a look at the file upload of the Laravel framework.

In fact, the Laravel framework of the file upload and our PHP source code file upload the same principle, recall, and then try to laravel frame upload it.

View: "The same as our original, enctype=" Multipart/form-data ""


Controller aspect:

The first thing to do is to answer the file: $file =request::file (' img ');

Verify that the upload file is valid:

if ($file->isvalid ()) {

Here's how to get file information

$clientName = $file->getclientoriginalname (); Get the name of the uploaded file

$tmpName = $file->getfilename (); File names that are cached in the TMP folder

$realPath = $file->getrealpath (); This represents the absolute path of the file that is cached in the TMP folder

$entension = $file->getclientoriginaextension (); Upload a file suffix

You can manually build a folder to store pictures

Give the picture a new name, the picture name stitching complete

$newName =rand (1,9999). ".". $entension;

Move a file to a specified folder

$file->move (' folder name ', $newName);

Then, after stitching the path, it will be put into storage.

}

Probably the file upload on this thing;

So, we lavarel the simple basic operation of the framework is introduced here ...

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.