Tp3.2 RESTFul weather information for generating XML, HTML, and JSON API interfaces based on region queries

Source: Internet
Author: User

1. On the Controller page:

<?php//  This class is automatically generated by the system for testing purposes only Namespace home\controller;use think\controller\restcontroller;class  indexcontroller extends restcontroller{    //Display Page      Public function index () {       //print_r ($this->_method);d ie;          $Name  = $_get[' data '];         if (!preg_match ("/^[a-za-z]+$/", $Name)) {             echo  "Incorrect input";d ie;        }         if (__ext__ ==  ") {              $type = "html";        }else{              $type =__ext__;         }        switch  ($this->_method) {                case  ' get ':  // get request processing Code                         if  (__ext__ ==  ' HTML ') {                  $html  =  $this->sel ($Name);                  $this->response ($html, ' html ');                 //echo  "HTML";             }elseif (__ext__  ==  ' xml ') {                   $xml  =  $this->sel ($Name);                  $this Response ($xml, ' xml ');                             }elseif (__EXT__   ==  ' json ') {                  $json  =  $this->sel ($Name);                  $this->response ($json, ' json ');             }                        break;             case  ' put ':  // put request processing Code                        break;                   case  ' Post ':  // post request processing Code                         break;              }       }    public function sel ($name) {        //print_r ($name);d ie;          $sheng  = m (' Sheng ');   //instantiation Table         $ City = m (' city ');         $xian  = m (' Xian ');         if ($name = = "China") {              $dAta= $sheng->select ();             return $ data;        }else{              $s _id = $sheng->getfieldbypyname ($name, ' id ');   //get Query province id             //print_r ($s _id);d ie;             //determine if the Save ID is empty, if the query is not empty, get the related data for the subordinate ID of the province              if (! $s _id== "") {                  $c _id[' p_id ']= $s _id;                      $datas  =  $city- >where ($c _id)->select ();                  //priNt_r ($datas);d ie;                 return  $datas;            }else{                  $city _id =$ City->getfieldbypyname ($name, ' id ');  //get City id  getfieldby  Query and return the value of a field based on a field   for example, getfieldbyname                  //print_r ($city _id);d ie;                 if (! $city _id== "") {                      $x _id[' p_id ']= $city _id;                      $data 1 =  $xian- >where ($x _id)->select ();                      //print_r ($data 1);                     return  $data 1;                 }else{                      $xian _id =  $city _id = $xian- >getfieldbypyname ($name, ' id ');                     //print_r ($xian _id);d ie;                     if (! $xian _id== "") {                           $CX_id[' id ']= $xian _id;                         //print_r ($cx _id);d ie;                           $data 2 =  $xian->where ($cx _id)->select ();                         //print_r ($ DATA2);d ie;                         return  $data 2;                     }else{                          echo  "There is no such area! ";                     }                }             }         }    }}

2, configuration file:

<?phpreturn array (    //' configuration item ' = ' config value '/*  database Settings  */      ' Db_type '                =>   ' MySQL ',     //  database type      ' Db_host '                 =>  ' 127.0.0.1 ', //  Server address      ' db_name '                 =>  ' News ',          //  database name      ' Db_user '                 =>  ' root ',      //  user name      ' DB _pwd '                 =>   ',           //  password      ' db_port '                 =>  ' 3306 ',         //  ports      ' url_router_on '    => true,  //Open Route      ' Url_route_rules ' =>array (               ' index/:d ata '  => array (' index/index ',  ' Status=1 '),     );? >









Tp3.2 RESTFul weather information for generating XML, HTML, and JSON API interfaces based on region queries

Related Article

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.