phazei
(Phazei)
September 21, 2009, 6:55pm
1
I found the view path, but I’m not too sure where to put the viewPath or how to format it. I want it to affect the entire controller, not just a single method, so I don’t want to have to set it in every method over and over again.
I want to use the default plus some:
$this->viewPath = $this->getViewPath().’/extra/’;
But I’m guessing I need to put it as something like this:
$controllername = $this->getId();
$this->viewPath = "application.view.{$controllername}.extra";
Where to I put that? Inside __construct?
I’d be worried about overwriting the default constructor, and if I called: parent::__constructor(); it would over write the viewPath.
I’m sure there’s a really simple answer, I’m just new to this. Help
Thanks
Edit:
I found the init() method, and tried it, but when I went to change the viewPath I get the error:
Property "ApplicationController.viewPath" is read only.
I’m lost now.
jayrulez
(Waprave)
September 21, 2009, 7:03pm
2
phazei:
I found the view path, but I’m not too sure where to put the viewPath or how to format it. I want it to affect the entire controller, not just a single method, so I don’t want to have to set it in every method over and over again.
I want to use the default plus some:
$this->viewPath = $this->getViewPath().’/extra/’;
But I’m guessing I need to put it as something like this:
$controllername = $this->getId();
$this->viewPath = "application.view.{$controllername}.extra";
Where to I put that? Inside __construct?
I’d be worried about overwriting the default constructor, and if I called: parent::__constructor(); it would over write the viewPath.
I’m sure there’s a really simple answer, I’m just new to this. Help
Thanks
you can set the view path for the current controller in the init method
public function init() {//your code here}
phazei
(Phazei)
September 21, 2009, 7:30pm
3
Well, this seems to work:
public function getViewPath() {
$controllername = $this->getId();
$newPath = "application.views.{$controllername}.extra";
$newPath = YiiBase::getPathOfAlias($newPath);
return $newPath;
}
Seems to be quite a lot just to put some stuff in a subdir.
Am I doing it wrong?
jayrulez
(Waprave)
September 21, 2009, 10:10pm
4
phazei:
Well, this seems to work:
public function getViewPath() {
$controllername = $this->getId();
$newPath = "application.views.{$controllername}.extra";
$newPath = YiiBase::getPathOfAlias($newPath);
return $newPath;
}
Seems to be quite a lot just to put some stuff in a subdir.
Am I doing it wrong?
Cant you just put the subdir in the statement for rendering the view? like
$this->render('subdir/viewfile');
?
phazei
(Phazei)
September 22, 2009, 6:54am
5
I could but I have a load of controllers that are kind of grouped together and I didn’t want to do that in every single method for like 6 controllers. If I change something, it’s easier to just switch that in one place.