English 中文(简体)
在CakePHP 1.2中,让一个控制器函数调用不同的控制器函数
原标题:Have one controller function call a different controller function in CakePHP 1.2

如何在内部使用doSearch()函数来调用Titles控制器中的getTitles()函数?

最佳回答

简短的回答是,你不应该这样做。您应该将其转移到您的标题模型中,或者将其放在组件或帮助程序中以供重用。

如果你确定你想直接调用控制器,Cake确实提供了一个方法

http://book.cakephp.org/2.0/en/controllers.html#Controller::requestAction

问题回答

没有理由去另一个控制器。

控制器应该主要从模型中调用方法。所以应该有一个包含您需要的方法的标题模型。

如果您需要更多帮助,请发布您的代码。

因此,答案是:

$this->requestAction( /controller/action/params );

制作想要重用组件的功能并不总是像Cakephp那样工作良好,没有引入Models和find(),并且设置->$另一种方法是将您的核心功能作为核心功能,然后返回$results,将此功能调用为$results=$this->;函数within_controller();因此您可以通过这种方式重用功能。我有时在尝试使用组件时也会遇到一些错误,在Cakephp中,组件非常适合使用独立的php脚本和代码。





相关问题
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 ...

热门标签