gpt4 book ai didi

mysql - cakephp3 从其他模型中选择 count(*)

转载 作者:行者123 更新时间:2023-11-29 11:44:53 24 4
gpt4 key购买 nike

我有3个型号Employees CustomersPartners

我想显示所有表的计数employees customerspartnersdashboard查看Employees型号。

EmployeesController.php

<?php

namespace App\Controller;

class EmployeesController extends AppController
{
public function dashboard()
{

}

}
?>

我是 cakephp 的新手,我根本不知道如何查询其他模型表。

请向我指出有关此内容的良好教程或文档。会有帮助的

最佳答案

我使用以下代码修复了它。

// Controller
$this->loadModel("Customer");
$query = $this->Customers->find('all', [
'conditions' => ['Customers.area_cd =' => $this->Auth->user('area_cd')]
]);
$entity_count[0] = $query->count();
$this->loadModel("Employee");
$query = $this->Employees->find('all', [
'conditions' => ['Employees.area_cd =' => $this->Auth->user('area_cd')]
]);
$entity_count[1] = $query->count();
$this->loadModel("Partner");
$query = $this->Partners->find('all', [
'conditions' => ['Partners.area_cd =' => $this->Auth->user('area_cd')]
]);
$entity_count[2] = $query->count();

$this->set(compact('entity_count'));

// View
<?= $entity_count[0] ?>

关于mysql - cakephp3 从其他模型中选择 count(*),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35130448/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com