首页 > 解决方案 > 控制器不工作

问题描述

路线:

$routes->connect('/textos',['controller' => 'Administracion', 'action' => 'textos']);

控制器:

class AdministracionController extends AppController {
  public function textos() {
    $this->set('textos', $this->Textos->find('all'));
  }
}

模型 ---> TextosTable

错误:调用布尔文件 /srv/www/cake-arbol/src/Controller/AdministracionController.php 上的成员函数 find() 行:20

第 20 行:$this->set('textos', $this->Textos->find('all'));

什么问题?名称表是 Textos

标签: controllercakephp-3.0

解决方案


问题在于线路$this->Textos->find('all')

您必须在使用之前加载模型 Textos,

use Cake\ORM\TableRegistry;

class AdministracionController extends AppController {
  public function textos() {
    $textos = TableRegistry::get('Textos');
    $this->set('textos', $textos->find('all'));
  }
}

推荐阅读