如何在CakePHP助手中导入表?

如何在CakePHP助手中导入表?,php,cakephp,Php,Cakephp,您好,我正在ZipcodeClassHelper.php中编写以下代码 public function get_zip_point($table,$zip) { App::import('Model','Driver_location'); $MyModel = new Driver_location(); $qry = $MyModel->find("all",array('conditions'=>array('zip'=>$zip))); pr($qr

您好,我正在ZipcodeClassHelper.php中编写以下代码

public function get_zip_point($table,$zip) {

  App::import('Model','Driver_location');
  $MyModel = new Driver_location();

  $qry = $MyModel->find("all",array('conditions'=>array('zip'=>$zip)));
  pr($qry); exit;
}
我收到了错误消息:

Error: Class 'Driver_location' not found
File: E:\xampp\htdocs\2014\cab-zone\cabs\app\View\Helper\ZipcodeClassHelper.php
Line: 25

这违反了MVC模式,您不能在视图中获取数据。您的模型也没有很好的命名,它不符合约定,应该是DriverLocation

将控制器中的数据设置为视图:

$this->set('whatever', $this->Model->find('...'));

学习博客教程,了解Cake如何使用其约定和MVC。

这违反了MVC模式,您无法在视图中获取数据。您的模型也没有很好的命名,它不符合约定,应该是DriverLocation

将控制器中的数据设置为视图:

$this->set('whatever', $this->Model->find('...'));

做博客教程,了解Cake如何与它的约定和MVC一起工作。

在不在控制器内的情况下用CakePHP加载模型可以这样做:

$ModelName = ClassRegistry::init('ModelName');
然后查询模型:

$result = $ModelName->find('all');

在不在控制器内的情况下,在CakePHP中加载模型可以这样做:

$ModelName = ClassRegistry::init('ModelName');
然后查询模型:

$result = $ModelName->find('all');

试用此应用程序::使用“驱动程序位置”、“模型”@sismaster出现相同错误。请尝试此应用::使用“驱动程序位置”、“模型”@西斯马斯特也犯了同样的错误。