在两个不同的控制器上使用相同的功能

I have two controllers on my website, let's call them MovieController and ReviewController.

What I want to do is to use one of MovieController's functions inside ReviewController.

The only thing I could think of is to extend MovieController instead of CController. However, it's hard for me to believe it's the right solution...

You have at least two options

1) Move the function to the main Controller, under components/Controller.php

class Controller extends CController {


2) Have another class extend from the above-mentioned main controller, and put your shared Movie/Review function inside it. Have both MovieController and ReviewController extend from this intermediate controller instead. Perhaps call it SharedController:

class SharedController extends Controller {

class MovieController extends SharedController {

class ReviewController extends SharedController {

You can: 1) create Helper class 2) use Traits/Behaviors etc..