English 中文(简体)
cakephp模型级的使用控制器方法
原标题:use controller method from model class in cakephp

In my cakephp project, I use afterSave() method of a model class. In this method, I want to call another method that is located in app_controller file.

class MyModel extends AppModel {

        var $name =  MyModel ;

        function afterSave($created) {

            $this->MyController->updateData();          
        }

}

Here updateData() is located in app_controller file, which is extended by MyController controller.

以上法典没有发挥作用,因此,如何真正地将最新数据称为Data(Data)案件。

Please guide.

增 编

最佳回答

强烈建议,但无论如何都可以这样做。 您应尝试用精练的言辞,将这种方法推向应用模型或任何其他特定模式......

you may use this function

适用:进口 查阅 这里的,以了解如何使用

例如:

class MyModel extends AppModel {

        var $name =  MyModel ;

        function afterSave($created) {
            App::import( Controller ,  My );
            $something = new MyController;
            $something->updateData();          
        }

}

这是在另一地点装上一等舱的正确方式。 尽管如此,您还是可以使用包括或要求,并创立一个类别的例子,因为这个类别是“所在地点”。

问题回答

暂无回答




相关问题
What do you have in your Model class?

What do you have in your model classes. Generally if i use any framework or any library (Zend Framework) , my classes only have variable which is table name . I know that in complicated applications ...

Rails Model With Aggregrate Data (not backed by a table)

Id like to create a model in rails that does not correlate to a table in the database. Instead the model should dynamically pull aggregrate data about other models. Example: I have a Restaurant ...

Trouble changing databases for my models in codeigniter

I m making a website with two different databases. Let s say one is DB1, and the other is DB2. I ve set up my database.php in the config folder, so they each have the correct host/password/username/...

EMAIL server FSP model

For my assignment I need to develop FSP model for email server and client. I manage to write simple model which describes one user, server and his mailbox, but I am having problems changing this ...

Rails Custom Model Functions

I m in a databases course and the instructor wants us to develop an e-commerce app. She said we can use any framework we like, and now that we re halfway through the semester she decided that Rails ...

热门标签