mirror of
https://github.com/processwire/processwire.git
synced 2025-08-24 07:13:08 +02:00
Fix issue processwire/processwire-issues#351 Fix Process.php setViewFile() method typo, and behavior improvements
This commit is contained in:
@@ -125,7 +125,8 @@ abstract class Process extends WireData implements Module {
|
||||
*
|
||||
* When any execute() method returns a string, it us used as the actual output.
|
||||
* When the method returns an associative array, it is considered an array of variables
|
||||
* to send to the output view layer.
|
||||
* to send to the output view layer. Returned array must not be empty, otherwise it cannot
|
||||
* be identified as an associative array.
|
||||
*
|
||||
* This execute() method is called when no URL segments are present. You may have any
|
||||
* number of execute() methods, i.e. `executeFoo()` would be called for the URL `./foo/`
|
||||
@@ -134,7 +135,10 @@ abstract class Process extends WireData implements Module {
|
||||
* @return string|array
|
||||
*
|
||||
*/
|
||||
public function ___execute() { }
|
||||
public function ___execute() {
|
||||
return ''; // if returning output directly
|
||||
// return array('name' => 'value'); // if populating a view
|
||||
}
|
||||
|
||||
/**
|
||||
* Hookable method automatically called after execute() method has finished.
|
||||
@@ -188,7 +192,7 @@ abstract class Process extends WireData implements Module {
|
||||
* ~~~~~
|
||||
*
|
||||
* @param string $headline
|
||||
* @return this
|
||||
* @return $this
|
||||
*
|
||||
*/
|
||||
public function ___headline($headline) {
|
||||
@@ -204,7 +208,7 @@ abstract class Process extends WireData implements Module {
|
||||
* ~~~~~
|
||||
*
|
||||
* @param string $title
|
||||
* @return this
|
||||
* @return $this
|
||||
*
|
||||
*/
|
||||
public function ___browserTitle($title) {
|
||||
@@ -221,7 +225,7 @@ abstract class Process extends WireData implements Module {
|
||||
*
|
||||
* @param string $href URL of breadcrumb
|
||||
* @param string $label Label for breadcrumb
|
||||
* @return this
|
||||
* @return $this
|
||||
*
|
||||
*/
|
||||
public function ___breadcrumb($href, $label) {
|
||||
@@ -299,8 +303,8 @@ abstract class Process extends WireData implements Module {
|
||||
*
|
||||
* #pw-group-module-interface
|
||||
*
|
||||
* @param $fromVersion Previous version
|
||||
* @param $toVersion New version
|
||||
* @param int|string $fromVersion Previous version
|
||||
* @param int|string $toVersion New version
|
||||
* @throws WireException if upgrade fails
|
||||
*
|
||||
*/
|
||||
@@ -493,10 +497,15 @@ abstract class Process extends WireData implements Module {
|
||||
*
|
||||
*/
|
||||
public function setViewFile($file) {
|
||||
$path = $this->wire('config')->paths . $this->className();
|
||||
if(strpos($file, $path) !== 0) $file = $path . ltrim($file, '/');
|
||||
if(strpos($file, '..') !== false) throw new WireException("Invalid view file");
|
||||
if(!is_file($file)) throw new WireException("View file $file does not exist");
|
||||
if(strpos($file, '..') !== false) throw new WireException("Invalid view file (relative paths not allowed)");
|
||||
$config = $this->wire('config');
|
||||
if(strpos($file, $config->paths->root) === 0 && is_file($file)) {
|
||||
// full path filename already specified, nothing to auto-determine
|
||||
} else {
|
||||
$path = $config->paths($this->className());
|
||||
if($path && strpos($file, $path) !== 0) $file = $path . ltrim($file, '/\\');
|
||||
if(!is_file($file)) throw new WireException("View file '$file' does not exist");
|
||||
}
|
||||
$this->_viewFile = $file;
|
||||
return $this;
|
||||
}
|
||||
|
@@ -267,7 +267,7 @@ class ProcessController extends Wire {
|
||||
}
|
||||
if(is_array($content)) {
|
||||
// array of returned content indicates variables to send to a view
|
||||
if(count($content)) {
|
||||
if(count($content) || $this->process->getViewFile()) {
|
||||
$viewFile = $this->getViewFile($this->process, $method);
|
||||
if($viewFile) {
|
||||
// get output from a separate view file
|
||||
|
Reference in New Issue
Block a user