Skip to content

Commit 3af8623

Browse files
committed
add: error feature for view controller
1 parent 63120a4 commit 3af8623

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

framework/View.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class View
1212
public $_outBuffer;
1313
public $_layout = 'default';
1414

15+
public $errors = [];
16+
1517
public function render($viewName, $data = [])
1618
{
1719
extract($data);
@@ -71,4 +73,57 @@ public function setLayout($path)
7173
{
7274
$this->_layout = $path;
7375
}
74-
}
76+
77+
/**
78+
* @method for setErrors
79+
*
80+
* @param $errors
81+
* @return void
82+
*/
83+
public function setErrors($errors)
84+
{
85+
$this->errors = $errors;
86+
}
87+
88+
/**
89+
* @method for getErrors
90+
*
91+
* @return array
92+
*/
93+
public function errors()
94+
{
95+
return $this->errors;
96+
}
97+
98+
/**
99+
* @method for hasErrors
100+
*
101+
* @return bool
102+
*/
103+
public function hasErrors()
104+
{
105+
return !empty($this->errors);
106+
}
107+
108+
/**
109+
* @method for get error by key
110+
*
111+
* @param $key
112+
* @return string
113+
*/
114+
public function error($key)
115+
{
116+
return $this->errors[$key] ?? '';
117+
}
118+
119+
/**
120+
* @method for check error by key
121+
*
122+
* @param $key
123+
* @return bool
124+
*/
125+
public function hasError($key)
126+
{
127+
return isset($this->errors[$key]);
128+
}
129+
}

0 commit comments

Comments
 (0)