控制器没工作

时间:2018-06-26 08:13:13

标签: controller cakephp-3.0

路线:

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

控制器:

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

模型---> TextosTable

  

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

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

什么问题?名称表是Textos

1 个答案:

答案 0 :(得分:1)

问题出在第$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'));
  }
}