我想在我的控制器中加载我的模型。该模型不会与数据库中的表关联,因此可能无法关注CakePHP的ORM。CakePHP:在控制器中加载模型
我已经目前下面的代码(这是我的模型):
<?php
namespace App\Model\Json;
use Cake\Filesystem\File;
class Processes
{
public static function getData()
{
$file = new File('process_data.json');
$json = $file->read(true, 'r');
$jsonstd = json_decode($json);
// remove STD classes
$json2array = json_decode(json_encode($jsonstd), true);
$cpu = array();
foreach ($json2array as $key => $row)
{
$cpu[$key] = $row['cpu_usage_precent'];
}
array_multisort($cpu, SORT_DESC, $json2array);
// return data
return $json2array;
}
}
我打电话,通过下面的代码模型(控制器):
$json2array = $this->Processes->getJson();
$this->set('data', $json2array);
我不能以某种方式在我的控制器中调用它。我不断收到以下错误:
Some of the Table objects in your application were created by instantiating "Cake\ORM\Table" instead of any other specific subclass.
Please try correcting the issue for the following table aliases:
Processes
没有一个CakePHP的用户,但我希望'AppModel'是与ORM一个CakePHP的类。因为你的班级没有使用orm,所以''AppModel'不是固有的' – Steve
你是怎么在你的控制器中调用它的?如果你使用'loadModel',不要。加载Table类,这不是一个表。 – ahoffner
我不会通过'loadModel'加载它,而是通过'$ this-> Processes',这很可能因为它与ORM相关而不起作用。 – h0sfx0