Skip to content
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 the _set_template_path for a more kohana conventional method/behav #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions classes/kohana/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,24 @@ public function __set( $key,$value )
/**
* Before the action gets executed we need run a few processes.
*
* @uses $this->_set_template_path
* @uses $this->template_path
* @return void
*/
public function before()
{

// Load the path that points to the view (if applicable)
$this->_set_template_path( $this->request->controller(), $this->request->action(), 'html' );
$this->template_path( $this->request->controller(), $this->request->action(), 'html' );

}

/**
* Renders the template if necessary
*
* @uses $this->_template_path
* @uses $this->__context
* @uses $this->_environment
* @uses $this->_auto_render
* @return void
*/
public function after()
Expand All @@ -135,24 +139,41 @@ public function after()
}

/**
* Load the path that points to the view (if applicable).
* We return a bool so that the method can be reused even
* if there's the need to extend the method
* Behave like kohana's getter/setter methods.
* The setter behaviour occurs when parameters are passed to the method.
* The getter behaviour occurs when no parameters are passed to the method.
*
*
* @param string $path Directory path
* @param string $file File name
* @param string $extension File Extension
* @param string $extension (optional) File Extension
* @uses $this->_template_path
* @usedby $this->before
* @return bool This boolean determines whether the file exists or not
* @return bool|string Under the setter behaviour, we return a boolean that determines whether the file exists or not.
* Under the getter behaviour, we return a string that determines the value of _template_path
*/
protected function _set_template_path($path,$file,$extension="html")
protected function template_path($path=NULL,$file=NULL,$extension="twig")
{
$exists = Kohana::find_file("views".DIRECTORY_SEPARATOR.$path,$file,$extension);
if( $exists )
if( $path === NULL AND $file === NULL )
{
return $this->_template_path;
}
else if( $path !== NULL AND $file !== NULL )
{
$exists = Kohana::find_file("views".DIRECTORY_SEPARATOR.$path,$file,$extension);
if( $exists )
{
$this->_template_path = $path.DIRECTORY_SEPARATOR.$file.".".$extension;
}
return $exists;
}
else
{
$this->_template_path = $path.DIRECTORY_SEPARATOR.$file.".".$extension;
throw new Kohana_Exception(
"Wrong number of parameters passed to the template_path method"
);
}
return $exists;

}

} // End Controller