I’ve done a simplified version, where I created a new installation of Yii which works perfectly. I created a new “ParentController.php” in “/htdocs/protected/controllers”, which is a basic class which looks like this:
class ParentController extends CController
public function __construct()
I then modified the existing SiteController.php class to it extended from ParentController instead of CController, like so:
So it appears it can’t find the “ParentController.php”. Having read & tried the example in the cookbook with exactly the same result (in that case, ExampleController can’t find ParentController), can anyone please tell me what I’m doing wrong?
Where should I be putting the "ParentController.php"?
Thanks in advance.
Update: Thanks to Y!! and jayrulez I’ve resolved this. It might be worth updating the tutorial I link to reflect that the parent controllers need to be placed in “/protected/components” and the config updated to allow other components to be loaded from this directory.
Thank you both for quick & helpful replies! Both approaches work perfectly, and make sense! I just wasn’t sure what the new class was classed as, if you get my meaning. I’ll be using jayrulez’s approach, purely for directory structure consistency.
So now, if I want to run some pre-processing on each page, I can do that in the ParentController, inside a function called init() (instead of __construct, which causes a headache). That’s perfect!
I’ve also managed to figure out how to bind data in the ParentController (using a method in that exact tutorial) that can be used in the sub-controllers view, which makes life very easy for what I want to do.