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.