Follow me to learn php (58) in oracle

Login logo

Usually also have to store the current logged-on user ( administrator) function information!

 

In memory when you log flag, the current administrator to obtain the information stored in the session in :

Back/AdminController->checkAction();

 

 

Need back / AdminModel-> check () method, the information returned for the administrator ( legitimate case):

 

 

In the back / PlatformController -> _ checkLogin ( ) in verification administrator whether the login, use admin index:

 

Exit , the destruction is also the sign:

Back/AdminController->logoutAction();

 

 

 

Page can get information on administrator:

Back / top.html, the display : Hello  Admin !

 

 

shop34-19- items to add

Function : Add commodity form

Index.php?p=back&c=Goods&a=add

Controller-Action:

New merchandise controller class

Application/back/controller/GoodsController.class.php

 

addAction()

 

Model:

View-template

Increase the view layer template:

Application/back/view/goods_add.html

It requires a corresponding of the JS :

 

Leaving a portion of the tab, and form elements:

 

 

supplement

Edit menu of menu.html template , add an action request:

Back/view/menu.html

 

Function : processing product add data

Index.php?p=back&c=Goods&a=insert

Controller - action

Back/GoodsController->insertAction();

Checkbox at submit time:

If the checked: if it is value attribute value .

If unchecked: the form does not provide post its data (_POST not the element)

 

Recommended :

Using naming array mode, and the value that needs to be inserted into the data table :

 

Treatment :

 

 

Achieve insertAction ();

 

model

For the goods creating tables operating model:

Application/back/model/GoodsModel.class.php

 

Format string:

Sprintf () can be completed for the format string:

Sprintf ( format , format the data required )

 

 

Tip : Data participation SQL execution, we must prevent SQL injection, use the escape!

At this point in the model level, we can provide all the data in the array, batch escaping functions:

Base model adds methods:

escapeStringAll();

 

 

You need to call the method:

Back/GoodsModel->insertGoods()

 

View - Templates

 

Supplementary :

Product List

 

 

 

shop34-20- table prefix processing

Model - the prefix processing

Real table name  = prefix ( project)  + Logical table name (function)

Prefix: Configuration via the configuration file.

Config/application.config.php

 

Logic table name : Model class itself determined.

Model class in increased property: _logic_table

 

 

Piece together the real table name:

Basic model, increase the initialization real operating table names:

 

Table name Backticks package!

 

Instantiated when the object model, the completion of initialization of the real table name:

Foundation construction method of the model:

 

 

Use real table name:

In the model , a patchwork of SQL statements when using the $ this -> _ table:

 

 

shop34-21- File Upload tool

File Upload

Upload :

From the browser to the server side transmitted.

Request:

Data from the end of the transmission the browser to the server.

 

Visible :

Upload , occurred in the browser makes a request to the server process.

 

File , for the browser is concerned, is in the form of a special type of data only.

 

Browser data in the form of : two kinds of types.

1,  the string type. ( Byte stream encoding)

2, file type. ( Binary-coded)

(Tip : file is the data in the form of a part).

 

Submit the form is, the browser automatically in the form of data, transmitted to the server, the file type will be included.

 

Server angle:

In an interview with the browser's request, handle the form in the data.

The different types of data (2 types), using a different approach:

1,  string type is stored in the $ _POST variable in (memory)

2, file type data, stored in the temporary directory upload.

 

 

Form the time of submission : the browser will default view that data in the form is a string type (even with file file domain ) , through the form on the increased property tells the browser the type of data in the form not only has a string.

Form enctype=”multipart/form-data”

 

 

PHP server after receiving the form data file type:

The file is stored in the temporary directory to upload . That is, temporary files, scripts within the validity period valid.

By PHP 's php.ini configuration :

 

The default for the server operating system temporary directory.

 

 

Require the temporary file upload persistent store! ( To move to a specified location)

Function :

Move_uploaded_file (upload temporary address, destination address );

carry out

Need to use the $ _FILES array , stores information temporary file uploads, including temporary address!

 

Each temporary file uploads, there are 5 Messages, name : the original file name , of the type : type, tmp_name , temporary address, error : if there are errors and error types , size : size.

 

 

Typical upload the code

By judgment of file attribute information, determines whether the file is available!

 

Type : representation  2 kinds:

Extension : file system, the program identifies the file.

The MIME (Multipurpose internet Mail Extensions): transport network resources, the resource type used representation.

Text/html; image/png

 

 

Extension intercepts:

$file = 'x.y.z.png';

echo strrchr($file, '.');

// find the last occurrence of a substring in the string position, and the position to be taken from the end of the string.

 

 

 

Array_merge () array merge

array_unique () to remove the array elements in duplicate value

 

Rename the file:

Use original name. ( Duplicate names, special characters , does not have the logical meaning)

Named : uniqid ();

Uniqid () may generate a unique string prefix and allowed to set.

 

 

 

Type detection:

Suffixes and MIME

More than two values, are provided by the browser request.

Need server PHP itself complete MIME detection:

Required PHP extensions:  FileInfo  complete detection information to the file.

It provides an object-oriented syntax and function of two sets:

The use of object-oriented syntax it:

Open this extension:

 

Apache restart

 

 

 

 

Molecular directory for storing uploaded files

Principle : the business logic. The number of files. According to time .

Mkdir (directory address ) to create a directory

Is_dir (directory address ) detect directory

 

Date () to get the date and time

 

 

 

 

Project used

Upload tools category :

 

Complete load automatically:

 

 

Add product use:

Back/GoodsController->insertAction();

 

Model , the processing goods_image_ori:

Back/GoodsModel->insertGoods();

 

Modify the form so that it can upload files and set file form elements, from the name.

Back/iew/goods_add.html

 

Guess you like

Origin www.cnblogs.com/RighTgraM/p/10971461.html