English 中文(简体)
CakePHP - 在HABTM中设置一个模型功能
原标题:CakePHP - Calling a model function in a HABTM

我有两张表格,页数和员额,都列在自动取款机上,并使用页数加入表。

我的页面模型与HABTM的定义包含一个功能。

class Page extends AppModel
{
   var $name = "Page";
   ......
   ......
   function callthis()
   {
     return $this->find( all );;
   }
}

我从我的员额控制员那里试图称职。

class PostsController extends AppController
{
    ....
    ....
    function index()
    {
      $returned = $this->Post->Page->callthis();
    }
}

结果是

Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near  threadedpages  at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 681]

进一步预测产出:

法典

        $out = null;
        if ($error) {
            trigger_error( <span style="color:Red;text-align:left"><b>  . __( SQL Error: , true) . "</b> {$this->error}</span>", E_USER_WARNING);

背景

$sql    =   "threadedpages"
$error  =   "1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near  threadedpages  at line 1"
$out    =   null

呼吁

DboSource::showQuery() - CORE/cake/libs/model/datasources/dbo_source.php, line 681
DboSource::execute() - CORE/cake/libs/model/datasources/dbo_source.php, line 266
DboSource::fetchAll() - CORE/cake/libs/model/datasources/dbo_source.php, line 410
DboSource::query() - CORE/cake/libs/model/datasources/dbo_source.php, line 364
Model::call__() - CORE/cake/libs/model/model.php, line 502
Overloadable::__call() - CORE/cake/libs/overloadable_php5.php, line 50
AppModel::threadedpages() - [internal], line ??
PostsController::admin_index() - CORE/plugins/cakey/controllers/posts_controller.php, line 11
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83

应在《基本生活标准》中规定相关的示范功能? 如果我们检查

$this->Recipe->Tag->find( all , array( conditions =>array( Tag.name => Dessert )));

当找到塔格模型的功能时,可以从相关的收款控制员那里召来,为什么我会从相关的员额控制员那里打电话给页模型。

最佳回答

正如斯蒂芬和莫雷诺指出的,我的关系确实存在问题。

http://book.cakephp。 如果我们需要在你的gin子里提及一种模式,我们需要把假名与模版名称分开。

我在不使用Plugin的情况下直接提到了这些模型。 模式为Name。 谢谢大家。

问题回答

这个问题在你的关系中最有可能发生。 您

$this->Post->Page->find( all );

你们仍然有错误。

• 确保在邮政管理处装上页码模型(在任何职能之前应靠近控制器的顶端):

var $uses = array( Post ,  Page );

然后,你们应该能够发出公正的呼吁。

$this->Page->callthis();

我有同样的问题。

I have added the PluginName.ModelName, then it is resolved. So adding a PluginName in front of the plugin model is very good practice,

Thanks, Vijay





相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

Using DISTINCT in a CakePHP find function

I am writing a CakePHP 1.2 app. I have a list of people that I want the user to be able to filter on different fields. For each filterable field, I have a drop down list. Choose the filter ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

Prevent controller from trying to autoload model

I am a beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call ...

热门标签