使用库中的模型cakephp [英] Use Model from inside a Library cakephp
本文介绍了使用库中的模型cakephp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在app / Lib文件夹中创建了几个文件,并想从库类中访问我的一个模型:
<?php
App :: uses('CrawlerBase','Lib');
App :: uses('Deal','Model');
class SampleCrawler extends CrawlerBase {
public $ uses = array('Deal');
function __construct(){
$ this-> Deal-> create();
然而,蛋糕似乎找不到交易模型和调用成员函数create
解决方案
div>
其他方式也可以这样做:
APP :: import('Model','Deal');
$ this-> Deal = new Deal();
$ this-> Deal-> create();
I created a few files in app/Lib folder and would like to access one of my models from the library classes:
<?php
App::uses('CrawlerBase','Lib');
App::uses('Deal', 'Model');
class SampleCrawler extends CrawlerBase {
public $uses = array('Deal');
function __construct(){
$this->Deal->create();
However, cake cant seems to find the Deal model and im getting a call to member function create() on a non-object in the model creation line.
Appreciate the help.
解决方案
Other way to also do this:
APP::import('Model', 'Deal');
$this->Deal = new Deal();
$this->Deal->create();
这篇关于使用库中的模型cakephp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文