Practical Essentials of curd application in thinkphp _php techniques

Source: Internet
Author: User

This is the main leisure to write about the specific application of curd, of course, the main side of the curd, I do is the user's additions and deletions, not with the three automatic

First of all

Copy Code code as follows:

Class Indexaction extends Action {
Public Function index () {
Header ("content-type:text/html; Charset=utf-8″);
$user =m (' user ');
$list = $user->select ();
$this->assign (' user ', $list);
$this->display ();
}

Show all users, homepage do registration

Copy Code code as follows:

Form action= "__url__/add" method= "POST" >
User name <input type= "text" name= "username" >
Password <input type= "text" name= "password" >
<input type= "Submit" value= "submitted" >
</form>
<volist name= "user" id= "VO" >
User name: <input name= "username" value= "<{$vo .username}>" >
Password: <input name= "password" value= "<{$vo .password}>" >
Registered Ip:<input name= "CIP" value= "<{$vo .cip}>" >
Registration time: <input name= "CTime" value= "<{$vo .ctime}>" >
<a href= "__url__/del/id/<{$vo .id}>" > Delete </a>
<a href= "__url__/edit/id/<{$vo .id}>" > Update </a>
<br>
</volist>

And then there is our deletion method is very simple thinking is like this we get ID delete this ID is ok

Copy Code code as follows:

if ($user->where (' $_get[' id ') ')->delete ())

{
$this->success (' delete success ');
}

That's it, okay?

Ways to add Users

Copy Code code as follows:

$user =m (' user ');
if ($user->create ()) {
$user->cip=get_client_ip ();
$user->ctime=time ();
$user->password=md5 (' password ');
if ($user->add ($data)) {
$this->success (' User registration Success ', '/admin.php/index/edit ');
}else{
$this->error ($user->geterror ());
}
}else{
$this->error (GetError ());
}

The update user is like this, we choose the user output information according to the ID

Copy Code code as follows:

$user =m (' user ');
$id = (int) $_get[' id '];
$user =m (' user ');
$list = $user->where ("id= $id")->find ();
$this->assign (' list ', $list);
$this->display ();

And then updating the user is simpler just one save

Copy Code code as follows:

$user =m (' user ');
if ($user->create ()) {
$user->ctime=time ();
if ($user->save ()) {
$this->success (' update successful ');
}
}else{
$this->error (' failure ');
}

This is the end of these parts will be able to complete the user's additions and deletions in fact, the simple function is our own added to the example

We go to the forum have landed how many times how to complete the fact that a setinc can be resolved landing once +1 such output landing

The number of times is OK

Here we go today.

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.