Home>

Using the tp framework is relatively simple,Before we wrote additions, deletions and changes,The amount of code is relatively large,It is very simple to write using the tp framework here,Greatly reduced code size

Here I take the nation table of the database as an example.The nation table has only two columns,One column is code and the other is name. First, add the add method.

functinon add ()
{
    if (empty ($_ post)) //First, we need to determine if there is a value passed
         {
              //If there is no value passed,Then just display the template,Create a file named add.html in the main folder under the view folder
             $this->show ();
          }
      else
      {
        //If there is a value passed,Need to collect information to add
         $n->d ("nation");
         $n->create ();
         if ($n->add ())
              {
                //has been added successfully,Need to jump to the page,Jump to a method
                $this->success ("Added successfully", "add", 3);
              }
        else
              {
                 $this->error ("Add failed");
               }
      }
}

Followed by the deletion method,The method of deletion is relatively simple,Just pass in a primary key value.

function del ($code)
{
   $n=d ("nation");
   $n->delete ($code);
}

Finally, the modified method,The modified method is relatively troublesome.Because when we open the interface that needs to be modified, there will be a default value.

function update ()
{
  $n=d ("nation");
  $arr=$n->find ($_ get ["b"])
  if (empty ($_ post))
    {
      $this->assign ("arr", $arr);//The value of the input code in the template page is {$arr.code} Similarly, the value of the input name is {$arr.name}
      $this->show ();
    }
   else
   {
      $n->create ();
     if ($n->save ())
       {
         $this->success ("Successfully modified", "add", 3);
       }
      else
       {
          $this->error ("Modification failed")
       }
   }
}
php
  • Previous Talking about object-oriented deep and shallow copy in JavaScript
  • Next Full exposure to the magic Bootstrap navigation bar combat articles