Php 在无脂肪框架中以数组形式返回一行不起作用

Php 在无脂肪框架中以数组形式返回一行不起作用,php,arrays,fat-free-framework,Php,Arrays,Fat Free Framework,我试图访问从MySQL返回的数组元素 控制器 模型 当我试图访问数组的元素时,比如so{{@category[category_title]}或{{{@category.category_title}}我有一个空页面 我做了一个{var_dump(@category)}}只是想看看是否有DB的响应,我得到了以下结果: array(1) { [0]=> object(Categories)#15 (11) { ["db":protected]=> object(

我试图访问从MySQL返回的数组元素

控制器 模型 当我试图访问数组的元素时,比如so
{{@category[category_title]}
{{{@category.category_title}}
我有一个空页面

我做了一个{var_dump(@category)}}只是想看看是否有DB的响应,我得到了以下结果:

array(1) {
  [0]=>
  object(Categories)#15 (11) {
    ["db":protected]=>
    object(DB\SQL)#9 (8) {
      ["uuid":protected]=>
      string(12) "onvh9nsstjk8"
      ["pdo":protected]=>
      object(PDO)#10 (0) {
      }
      ["dsn":protected]=>
      string(54) "mysql:host=localhost;dbname=dev.sp19789"
      ["engine":protected]=>
      string(5) "mysql"
      ["dbname":protected]=>
      string(26) "dev.sp19789"
      ["trans":protected]=>
      bool(false)
      ["rows":protected]=>
      int(1)
      ["log":protected]=>
      string(381) " (0.6ms) SELECT `category_id`,`category_title`,`category_nav_title`,`category_slug`,`parent_category_id` FROM `categories` WHERE category_slug='Products'
"
    }
    ["engine":protected]=>
    string(5) "mysql"
    ["source":protected]=>
    string(10) "categories"
    ["table":protected]=>
    string(12) "`categories`"
    ["_id":protected]=>
    NULL
    ["fields":protected]=>
    array(14) {
      ["category_id"]=>
      array(9) {
        ["type"]=>
        string(16) "int(10) unsigned"
        ["pdo_type"]=>
        int(1)
        ["default"]=>
        NULL
        ["nullable"]=>
        bool(false)
        ["pkey"]=>
        bool(true)
        ["value"]=>
        int(1)
        ["initial"]=>
        int(1)
        ["changed"]=>
        bool(false)
        ["previous"]=>
        int(1)
      }
      ["category_title"]=>
      array(8) {
        ["type"]=>
        string(12) "varchar(255)"
        ["pdo_type"]=>
        int(2)
        ["default"]=>
        NULL
        ["nullable"]=>
        bool(false)
        ["pkey"]=>
        bool(false)
        ["value"]=>
        string(15) "Products"
        ["initial"]=>
        string(15) "Products"
        ["changed"]=>
        bool(false)
      }
      ["category_nav_title"]=>
      array(8) {
        ["type"]=>
        string(12) "varchar(255)"
        ["pdo_type"]=>
        int(2)
        ["default"]=>
        NULL
        ["nullable"]=>
        bool(false)
        ["pkey"]=>
        bool(false)
        ["value"]=>
        string(0) ""
        ["initial"]=>
        string(0) ""
        ["changed"]=>
        bool(false)
      }          
      ["category_slug"]=>
      array(8) {
        ["type"]=>
        string(12) "varchar(100)"
        ["pdo_type"]=>
        int(2)
        ["default"]=>
        NULL
        ["nullable"]=>
        bool(false)
        ["pkey"]=>
        bool(false)
        ["value"]=>
        string(14) "products"
        ["initial"]=>
        string(14) "products"
        ["changed"]=>
        bool(false)
      }
      ["parent_category_id"]=>
      array(9) {
        ["type"]=>
        string(16) "int(10) unsigned"
        ["pdo_type"]=>
        int(1)
        ["default"]=>
        NULL
        ["nullable"]=>
        bool(false)
        ["pkey"]=>
        bool(true)
        ["value"]=>
        int(1)
        ["initial"]=>
        int(1)
        ["changed"]=>
        bool(false)
        ["previous"]=>
        int(1)
      }
    }
    ["adhoc":protected]=>
    array(0) {
    }
    ["props":protected]=>
    array(0) {
    }
    ["query":protected]=>
    array(1) {
      [0]=>
      object(Categories)#12 (11) {
        ["db":protected]=>
        object(DB\SQL)#9 (8) {
          ["uuid":protected]=>
          string(12) "onvh9nsstjk8"
          ["pdo":protected]=>
          object(PDO)#10 (0) {
          }
          ["dsn":protected]=>
          string(54) "mysql:host=localhost;dbname=dev.sp19789"
          ["engine":protected]=>
          string(5) "mysql"
          ["dbname":protected]=>
          string(26) "dev.sp19789"
          ["trans":protected]=>
          bool(false)
          ["rows":protected]=>
          int(1)
          ["log":protected]=>
          string(381) " (0.6ms) SELECT `category_id`,`category_title`,`category_nav_title`,`category_slug`,`parent_category_id` FROM `categories` WHERE category_slug='Products'
"
        }
        ["engine":protected]=>
        string(5) "mysql"
        ["source":protected]=>
        string(10) "categories"
        ["table":protected]=>
        string(12) "`categories`"
        ["_id":protected]=>
        NULL
        ["fields":protected]=>
        array(14) {
          ["category_id"]=>
          array(9) {
            ["type"]=>
            string(16) "int(10) unsigned"
            ["pdo_type"]=>
            int(1)
            ["default"]=>
            NULL
            ["nullable"]=>
            bool(false)
            ["pkey"]=>
            bool(true)
            ["value"]=>
            int(1)
            ["initial"]=>
            int(1)
            ["changed"]=>
            bool(false)
            ["previous"]=>
            int(1)
          }
          ["category_title"]=>
          array(8) {
            ["type"]=>
            string(12) "varchar(255)"
            ["pdo_type"]=>
            int(2)
            ["default"]=>
            NULL
            ["nullable"]=>
            bool(false)
            ["pkey"]=>
            bool(false)
            ["value"]=>
            string(15) "Products"
            ["initial"]=>
            string(15) "Products"
            ["changed"]=>
            bool(false)
          }
          ["category_nav_title"]=>
          array(8) {
            ["type"]=>
            string(12) "varchar(255)"
            ["pdo_type"]=>
            int(2)
            ["default"]=>
            NULL
            ["nullable"]=>
            bool(false)
            ["pkey"]=>
            bool(false)
            ["value"]=>
            string(0) ""
            ["initial"]=>
            string(0) ""
            ["changed"]=>
            bool(false)
          }
          ["category_slug"]=>
          array(8) {
            ["type"]=>
            string(12) "varchar(100)"
            ["pdo_type"]=>
            int(2)
            ["default"]=>
            NULL
            ["nullable"]=>
            bool(false)
            ["pkey"]=>
            bool(false)
            ["value"]=>
            string(14) "products"
            ["initial"]=>
            string(14) "products"
            ["changed"]=>
            bool(false)
          }
          ["parent_category_id"]=>
          array(9) {
            ["type"]=>
            string(16) "int(10) unsigned"
            ["pdo_type"]=>
            int(1)
            ["default"]=>
            NULL
            ["nullable"]=>
            bool(false)
            ["pkey"]=>
            bool(true)
            ["value"]=>
            int(1)
            ["initial"]=>
            int(1)
            ["changed"]=>
            bool(false)
            ["previous"]=>
            int(1)
          }
        }
        ["adhoc":protected]=>
        array(0) {
        }
        ["props":protected]=>
        array(0) {
        }
        ["query":protected]=>
        array(0) {
        }
        ["ptr":protected]=>
        int(0)
        ["trigger":protected]=>
        array(0) {
        }
      }
    }
    ["ptr":protected]=>
    int(0)
    ["trigger":protected]=>
    array(0) {
    }
  }
}
在我看来,数组中有两个相同的元素,而实际上应该只有一个

ATM,我只能显示类别标题,如so
{{@Category[0][Category_Title]}


任何简化查询的建议都会有帮助

查询似乎返回了两个结果。如果是这种情况,那么
{{@category[0][category_title]}
确实是正确的解决方案。您可能还希望对数据库查询使用限制


我要确保使用模型与数据库交互,并将0索引结果返回给控制器。

查询似乎返回了两个结果。如果是这种情况,那么
{{@category[0][category_title]}
确实是正确的解决方案。您可能还希望对数据库查询使用限制


我会确保使用一个模型与数据库交互,并将0索引结果返回给控制器。

当您从数据库中获取行时,您会得到一个数组,其中键作为从数据库返回的行的计数,值是来自数据库的数据。。因此,如果您选择只获取一行,那么数组将包含一个键(0)和categories值,因此数据将通过

@category[0][category_title]
只需在var中处理它,如:

$category = @category[0]

当您从数据库获取行时,您将获得一个数组,其中的键作为从数据库返回的行的计数,这些值是来自数据库的数据。。因此,如果您选择只获取一行,那么数组将包含一个键(0)和categories值,因此数据将通过

@category[0][category_title]
只需在var中处理它,如:

$category = @category[0]
方法
getBySlug()
应返回
$this
,除此之外:

public function getBySlug($category_slug)
{
    $this->load(array('category_slug=?', $category_slug));
    return $this;
}
方法
getBySlug()
应返回
$this
,除此之外:

public function getBySlug($category_slug)
{
    $this->load(array('category_slug=?', $category_slug));
    return $this;
}

要返回普通对象,应执行强制转换

public function getBySlug($category_slug)
{
    $this->load(array('category_slug=?', $category_slug));
    return $this->cast();
}

要返回普通对象,应执行强制转换

public function getBySlug($category_slug)
{
    $this->load(array('category_slug=?', $category_slug));
    return $this->cast();
}

我该怎么做?我刚刚用我的模型脚本更新了我的问题
$category\u slug=$this->f3->get('PARAMS.category\u slug')
是一个数据库调用,应该在它自己的模型方法中。这是进入设计决策,而不是你的具体问题。我过去使用过无脂框架,它很坚固。我强烈建议您使用更结构化的MVC来更好地了解如何构建它。CodeIgniter将是F3的一个非常小的跳跃。我应该怎么做?我刚刚用我的模型脚本更新了我的问题
$category\u slug=$this->f3->get('PARAMS.category\u slug')
是一个数据库调用,应该在它自己的模型方法中。这是进入设计决策,而不是你的具体问题。我过去使用过无脂框架,它很坚固。我强烈建议您使用更结构化的MVC来更好地了解如何构建它。CodeIgniter将是F3的一个非常小的跳跃。你的意思是在控制器方法内吗?你的意思是在控制器方法内吗?