• 使用模型查询数据之getAttr()


    查询分为两种方式,一种是Db查询,一种是模型查询。

    Login.php

    <?php 

    namespce appindexcontroller;

    use thinkController;

    use thinkLoader;

    use appindexmodelData;

    class Login extends Controller

    {

      public function _initialize()

      {

        $this->data=Loader::model('data');

      }

      public function test()

      {

        $model=new Data();

        $data=$this->data->getMenu();

        //data()方法完成前面模型对象的$data属性赋值  //使模型对象转换成数据对象,现在$model 已经是数据对象啦

        $model->data($data[0]);

        $res=$model->getAttr('node_name');

        dump($res);  //管理员管理

      }

    }

    data()方法,将模型对象转化成数据对象

    getAttr()方法,获取一维的索引数组的某个字段的值

    Data.php

    <?php

    namespace appindexmodel;

    use thinkDb;

    use thinkModel;

    class Data extends Model

    {

      protected $table='data';

      public function getMenu()

      {

        $res=Db::name($this->table)->select();

        return $res;

      }

    }

  • 相关阅读:
    使用SVG symbols建立图标系统完整指南
    ural 1874 Football Goal
    ural 1572 Yekaterinozavodsk Great Well
    ural 1084 Goat in the Garden
    ural 1192 Ball in a Dream
    ural 1020 Rope
    ural 1494 Monobilliards
    ural 1671 Anansi's Cobweb
    ural 1613 For Fans of Statistics
    ural 1126 Magnetic Storms
  • 原文地址:https://www.cnblogs.com/ymdphp/p/10949136.html
Copyright © 2020-2023  润新知