Twig和Medoo之 与CI框架有个约会

CI框架


  • 介绍

    优雅的CodeIgniter,称之为CI框架,CodeIgniter 是一个小巧但功能强大的 PHP 框架,作为一个简单而“优雅”的工具包,它可以为开发者们建立功能完善的 Web 应用程序。

  • 安装

    https://codeload.github.com/bcit-ci/CodeIgniter/zip/3.0.2  
    

    下载解压即可使用

  • 文档

      http://codeigniter.org.cn/user_guide/general/controllers.html#hello-world
    
  • 配合Medoo 和 Twig 飞起来

  • 查 多条
      $students = $this->db->select("ci_student", "*");
          
      echo $this->twig->render(
          'index.html',
          array(
              'page_title' => '主页',
              'students' => $students
          )
      );
    

    传递参数到index.html

    index.html 这个来解析

    {% for item in students %}

    {% endfor %}

    用过django的同学可以非常舒服的过渡到twig模板引擎,因为写法几乎是一样。

  • 查一条
      $student = $this->db->get('ci_student', "*", ["id"=>$id]);
    
      echo $this->twig->render(
              'edit.html',
              array(
                  'student' => $student,
              )
      );
    
  •   $id = $this->input->post('id');
      $name = $this->input->post('name');
      $age = $this->input->post('age');
    
      $this->db->update("ci_student",
      [
          "name" => $name,
          "age"  => $age
      ],
      [
          "id" => $id
      ]);
    

$this->input->post('id')

这样写就是获取post方式的数据

  •   public function del($id)
      {
          $this->db->delete("ci_student",
          [
          "id" => $id
          ]);
      }
    

    这样的写法,就是获取get方式的数据

  •   $name   = $this->input->post('name');
      $age    = $this->input->post('age');
    
      $this->db->insert("ci_student",
      [
          "name" => $name,
          "age"  => $age
      ]);

你可能感兴趣的:(Twig和Medoo之 与CI框架有个约会)