空值而不是 CodeIgniter 中的值

Null values instead of an Value in CodeIgniter

我有这段代码返回 NULL 而不是值。这是我的名为 Agents 的控制器,此代码在管理员端运行,但是当我将代码用于 Agents 用户级别时,它返回 NULL:

<?php namespace App\Controllers;


use App\Models\ClientModel;

class Agent extends BaseController{


    public $modelClients;


    public function __construct(){

        $this->modelClients = new ClientModel();



    }

function getClientsToAgent($id){

        $data = ([          
            "title" => "Lead Generation",
            "client" => $this->modelClients->where("clientsId", $id)->first(),
            "tasks" => $this->modelTasks->orderby("taskId", "ASC")->findAll()
        ]);
        echo view('agentTemplate/header',$data);
        echo view('agents/loadLeadGenView');
        echo view('agentTemplate/footer');
    }

}

在我名为 loadLeadGenView 的视图中:

 <?php 

    var_dump($client);
 ?>

这是我的模型名称 ClientModel:

<?php namespace App\Models;

use CodeIgniter\Model;

class ClientModel extends Model{

    protected $table = "tblclients";

    protected $primaryKey = "clientsId";

    protected $returnType = 'array';

    protected $allowedFields = ["clientsId","clientsFirstname","clientsMiddlename", "clientsLastname","clientsBusinessName","clientsCampaignGoals","clientsDateStarted","clientsJointVenture","clientsEmailAddress"];

}

我的另一个 Routes.php:

$routes->get('agents/getClientsToAgent/(:num)', 'Agents::getClientsToAgent/()');

这就是我想知道的原因。为什么它返回 NULL 而不是值?

修复你的路线,移除 $1 周围的括号

$routes->get('agents/getClientsToAgent/(:num)', 'Agents::getClientsToAgent/');

https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#examples