Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Need Help Calling Model Method From Another Controller

$
0
0
I have a model A that has logic to connect to an API and then create some new records in the database.

A user enters a website url into a table and the model creates a series of other data using information from the API, most
of this happens in the beforeSave() method. It does call some methods in the model using $this->method().

I now have a need to do something similiar to create missing data for a given url via the API, but from a different controller.

I don't want to clone the code completely in model B so I thought I would call a new method in Model A from Controller B.

I have found that $this-> refers to the current controller B and put simply it all falls apart really fast.

I was able to change a couple of $this->method() to self::method() but
I am trying to understand what is the best approach in Yii to solve this problem.

Any suggestions or links to information would be appreciated.

Cheers !

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>