我创建了一个注册表并将数据发送到 Controller 。
我想将此数据插入到 3 个不同的表(模型)中。
如何做到这一点?
最佳答案
您的意思(在 CakePHP 中)是您想要 使用 比默认型号更多的型号。默认模型是与您的 Controller 一样命名的模型。
为了实现你想要的,你只需声明一个变量 $uses
在您的 Controller 中。它是这样完成的:
<?php
class ExampleController extends AppController {
var $name = 'Example';
// $uses is where you specify which models this controller uses
var $uses = array('Model1', 'Model2', 'ModelN');
// ... here go your controller actions (methods)
}
?>
这将允许您的 Controller 使用
Model1
, Model2
和 ModelN
.重命名它们并根据您的需要添加更多。如果您不想在 Controller 中使用模型,您可以指定
$uses
到一个空数组,即:var $uses = array();
根据您使用的版本查看相应的 CakePHP 书籍章节:
controller::$uses
关于cakephp - 如何在 CakePHP Controller 中使用多个模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5869181/