如何加载模型? [英] How to load a model?
本文介绍了如何加载模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何加载模型?我已经尝试了几次,但是没有用.
How can I load a model? I have tried several times but it doesn't work.
我的代码是:
<?php
class NotesController extends AppController {
var $name='Notes';
var $helpers = array('Html','Form','Ajax','Javascript');
var $uses = array('note');
var $components = array('ModelLoader');
function index(){
$this->ModelLoader->setController($this);
$result = $this->params['url']['obj'];
//print_r($result);
$ee=$this->ModelLoader->load('note');
$pass = $this->note->search($result);
推荐答案
将自动加载模型,并可以在控制器功能的 $ this-> ModelName
上访问该模型.要加载的模型由控制器的名称决定,NotesController会自动加载Note模型.其他模型可以通过 var $ uses = array('Model')
;
The model is automatically loaded and accessible at $this->ModelName
in controller functions. Which model to load is determined by the name of the controller, NotesController automatically loads the Note model. Other models can be loaded via var $uses = array('Model')
;
class NotesController extends AppController {
var $name='Notes';
var $helpers = array('Html','Form','Ajax','Javascript');
function index() {
$this->Note->someaction(); // Accessing the model
}
}
也许您应该遵循本教程首先.
这篇关于如何加载模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文