New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change some properties to protected in CTheme. #1759
Comments
What exactly are you trying to achieve? What this "my own theme handler" would change? |
This is my ATheme class. This is what I try to achieve: class ATheme extends CTheme
{
public function setName($value)
{
$this->_name = $value;
}
/**
* Finds the view file for the specified controller's view.
* @param CController $controller the controller
* @param string $viewName the view name
* @return string the view file path. False if the file does not exist.
*/
public function getViewFile($controller, $viewName)
{
$moduleViewPath = $this->getViewPath();
if (($module = $controller->getModule()) !== null) {
$moduleViewPath = $module->getBasePath() . '/themes/' . $this->getName() . '/views/' . $controller->getId();
}
return $controller->resolveViewFile($viewName, $this->getViewPath().'/'.$controller->getUniqueId(), $this->getViewPath(), $moduleViewPath);
}
/**
* Finds the layout file for the specified controller's layout.
* @param CController $controller the controller
* @param string $layoutName the layout name
* @return string the layout file path. False if the file does not exist.
*/
public function getLayoutFile($controller, $layoutName)
{
$moduleViewPath = $basePath=$this->getViewPath();
$module = $controller->getModule();
if (empty($layoutName)) {
while ($module !== null) {
if($module->layout === false)
return false;
if(!empty($module->layout))
break;
$module = $module->getParentModule();
}
if($module === null) {
$layoutName = Yii::app()->layout;
}
else {
$layoutName = $module->layout;
$moduleViewPath = $module->getBasePath() . '/themes/' . $this->getName() . '/views';
}
}
else if($module !== null) {
$moduleViewPath = $module->getBasePath() . '/themes/' . $this->getName() . '/views';
}
return $controller->resolveViewFile($layoutName, $moduleViewPath.'/layouts', $basePath, $moduleViewPath);
}
} |
I would like to extend this request to all private properties from CDbCommand. If they were private, I could easily circumvent http://www.yiiframework.com/forum/index.php/topic/37911-call-of-yiilog-in-cdbcommandexecute/ Like it is right now, it's next to impossible. |
flesh: you mean "if they were protected" I think :) |
Oh, haha, thanks yes ;) |
There is a good reason for many framework properties to be private. This allows to change code behind the api without breaking behavior of a class. In most cases there are getters and setters that allow you to access the private properties. You might also want to read this: http://fabien.potencier.org/article/47/pragmatism-over-theory-protected-vs-private |
@cebe this time it's a specific request. |
If you want to make the theme name writable, you can overwrite getName() which returns your own $theme variable, and you then add setName() which sets your $theme variable. Yes, it looks cumbersome, but it is because the name property is read-only by design and you are trying to break this limit. |
Currently CTheme.php has this properties with private access:
private $_name;
private $_basePath;
private $_baseUrl;
I request the Yii team to modify them so they are protected:
protected $_name;
protected $_basePath;
protected $_baseUrl;
In order to use them in any class which extends CTheme and needs access to the properties mentioned above. For instance, the theme name could be changed at any time based on dinamic input or certain conditions.
The text was updated successfully, but these errors were encountered: