赵东昊--第二周一周总结

阅读数:1013 发布时间:2016-07-23 12:01:08

作者:w3zdh 标签: 心得 体会 收获 困难

总结

堂主还告诉我们着两句话:

1.任何语言都是对某种任务[目标]的想象的解决方案。
2.任何语言都要面对基本的IO存储、通信、计算、渲染。

通过着两句话给我们提供了很好的学习语言的一个方式,任何一种语言的学习都可以从这四个角度去学习,这样就很系统了。之后对微信的公众号的静默授权以及用户授权登录进行学习。当用户对公众号授权之后,公众号就可以获得一个access_token,通过access_token公众号可以获取微信用户的身份信息。

通过对微信这一机制的了解,我觉得微信早早的就开始在下一盘大棋。它先获得大量的用户,然后开房公众号这一平台,使得大量开发者入驻,来给各种用户开发内嵌在微信内的应用程序。它掌握着最重要的资源--用户,开发者都来给它的用户开发应用程序。而且这样的应用有不少好处,首先用户不用下载程序安装,不用注册,登录也方便,也不用考虑安全问题,对于开发者来说,他们不用存储大量的用户数据以及数据安全问题,节省成本又开发方便。所以对于用户来说是更愿意用公众号的相较于去下软件在注册登录。试想一下,如果这么壮大下去,大家手机只要下个微信解决一切了。微信就是建立了一个大的生态,用户和应用都入驻域这一环境之中,他就是这个世界的神管理着这一切。我觉得要开发一个好的有影响力的工程,不光要有知识的广度和深度,还要有远见,要看得长远,未来的发展。还有就是用户,你的产品一定是给人用的,只有抓在了用户,你才是王。

代码

<?php
// 定义文件上传根目录
define('UPLOAD_PATH', substr( __DIR__, 0, strrpos(__DIR__,DIRECTORY_SEPARATOR)) .DIRECTORY_SEPARATOR."daiyanren_server_phalcon/images/".DIRECTORY_SEPARATOR );
// echo UPLOAD_PATH;
// 变量打印
function dump($data){
    echo "<pre>";
    var_dump($data);
    echo "</pre>";
}
try {
    $di = new PhalconDIFactoryDefault();
    $di->set('db', function(){
        return new PhalconDbAdapterPdoMysql(array(
            "host" => "192.168.0.103",
            "username" => "root",
            "password" => "",
            "dbname" => "xiuwai_database",
            "charset" => "utf8",
            'unix_socket' => '/tmp/mysql.sock'
        ));
    });
  $loader = new PhalconLoader();
    $loader->registerDirs(array(
        __DIR__ . '/models/'
    ))->register();

    class BaseModel extends PhalconMvcModel
    {
       public $db;
       public function initialize()
       {
          $this->db = $this->getDi()->getShared('db');
          return $this->db;
       }
    }

    class Users extends BaseModel // Users extends out BaseModel and will have access to $db
    {
        /**
         * 试着拿一个值
         * @param  字符串 $sql 生成的查询语句
         * @return 数组      返回的数据集
         */
       public function test($sql)
       {
          // print_r(PhalconDi::getDefault()->getShared('db')); // This is the ugly way to grab the connection.

          $result=$this->db->query($sql); // Working now
          // echo $result->numRows();
          $rs = $result->fetchAll();
          return $rs;
       }
    }

    $app = new PhalconMvcMicro($di);

    //Retrieves all robots
    $app->get('/api/task/{uid}', function($uid) use ($app) {
    $phql =  "select task.task_id as order_id,task.number as task_num,user.user_name as usr_name,user.user_portrait as avatar,code.name as address,task.starttime as starttime,goods.dis_price_rmb*task.number as total_price,task.buyer_id as buyer_id"
    ." from task,user,address,code,goods"
    ." where task.buyer_id=user.user_uid and task.address_id=address.address_id and address.code_id=code.code_id and task.goods_id=goods.goods_id";
    $rows = $app->modelsManager->executeQuery($phql);
    $tasks = array();
    $nt = strtotime(date("Y-m-d H:i:s"));
    $i = 0;
    foreach ($rows as $row) {
      $rel = 0;
      $phql = "select * from fans where fans_id=".$row->buyer_id." and focus_id=".$uid;
      $rsfs = $app->modelsManager->executeQuery($phql);
      $rsf = $rsfs->getFirst();
      if($row->buyer_id == $uid)
      {
        $rel = 0;
      }else{
        if(empty($rsf)){
            $rel = 3;//bu shi fans
        }else{
            $rel = 1;//shi fans
        }
      }
      $tj['order_id'] = $row->order_id;
      $tj['avatar'] = $row->avatar;
      $tj['usr_name'] = $row->usr_name;
      $tj['relative'] = (string)$rel;
      $tj['address'] = $row->address;
      $tj['task_num'] = $row->task_num;
      $tj['total_price'] = $row->total_price;
      $tj['order_time'] = (string)($allt - ($nt - strtotime($row->starttime)));

      $tasks[$i] = $tj;
      $i ++;
    }

    $feedback['status'] = 1;
    $feedback['msg'] = 'ok';
    $feedback['data']['pagecount'] = '100';
    $feedback['data']['currentpage'] = '12';
    $feedback['data']['data'] = $tasks;
    $feedback['timeSpend'] = 'timeSpend';

    die(json_encode($feedback));
    });

    //Retrieves robots based on primary key
    $app->get('/api/robots', function($id) {
    echo " I am get";
    });

    //Adds a new robot
    $app->post('/api/robots', function() {
        $request = new PhalconHttpRequest();
        // 判断是否是post
        if ($request->isPost() == true) {
            // 判断是否是Ajax
            if ($request->isAjax() == true) {
                    echo "Ajax";
            }else{
                echo " I am POST";
                //recive data
                echo $request->get("mypic");
                echo $request->get("name");
                echo $request->get("password");

                //use data
                $phql = "SELECT * FROM employee";
                $rows = $app->modelsManager->executeQuery($phql);
                    foreach ($rows as $row) {
                    echo $row->name."<br>";
                }

                // do something

                // return data;
            }
        }
        // 检查是否有文件上传
        // if ($request->hasFiles() == true) {
        //     // 打印文件信息
        //     foreach ($request->getUploadedFiles() as $file) {
        //         dump($file);

        //         object(PhalconHttpRequestFile)#41 (8) {
        //           ["_name":protected]=>
        //           string(44) "test.jpg"
        //           ["_tmp":protected]=>
        //           string(21) "C:Windowsphp6B7.tmp"
        //           ["_size":protected]=>
        //           int(78029)
        //           ["_type":protected]=>
        //           string(10) "image/jpeg"
        //           ["_realType":protected]=>
        //           NULL
        //           ["_error":protected]=>
        //           int(0)
        //           ["_key":protected]=>
        //           string(5) "photo"
        //           ["_extension":protected]=>
        //           string(3) "jpg"
        //         }

        //         // 上传文件名
        //         echo "上传文件名:".$file->getName()."<br />";
        //         // echo "临时文件路径:".$file->getTmp()."<br />";
        //         // 打印临时文件路径时报错 没有该方法
        //         // 手册中也没有提供详细的说明  如果知道请留言!
        //         echo "文件大小:".$file->getSize()."<br />";
        //         echo "文件类型:".$file->getType()."<br />";
        //         echo "错误代码:".$file->getError()."<br />";
        //         echo "上传表控件名:".$file->getKey()."<br />";
        //         echo "文件后綴".$file->getExtension()."<br />";

        //         // 移动到指定目录
        //         $file->moveTo(UPLOAD_PATH.$file->getName());

        //     }
        // }
    });

    //Updates robots based on primary key
    $app->put('/api/robots/{id:[0-9]+}', function() {
  //$app->put('/api/robots', function() {
    echo " I am put";
    });

    //Deletes robots based on primary key
    $app->delete('/api/robots/{id:[0-9]+}', function() {
  //$app->delete('/api/robots', function() {
    echo " I am delete";

    });

    $app->handle();
} catch (Exception $e) {
    echo $e->getMessage();
}

相关文章推荐: