我必须在CompanyController->create()
中重定向:
class CompanyController extends \BaseController {
...
public function index(){
echo var_dump(Session::get('err'));
}
...
public function create()
{
if($validator->passes()){
$this->setError("no errors");
}else{
$this->setError("Some errors occurred: ");
foreach($validator->messages()->all() as $msg)
$this->setError($msg);
}
return Redirect::action('CompanyController@index');
}
}
我的BaseController类看起来像这样:
class BaseController extends Controller {
private $errors = array();
protected $view_params = array();
function __construct() {
if(Session::has('err')){
$this->errors = Session::get('err');
$this->view_params['err'] = $this->errors;
}
}
...
protected function setError($str){
if(!isset($this->view_params['err']) || $this->view_params['err']==null)
$this->view_params['err']=array();
if(!isset($this->errors) || $this->errors==null)
$this->errors=array();
array_push($this->view_params['err'],$str);
array_push($this->errors,$str);
Session::put('err',$this->errors);
}
protected function getErrors(){
return $this->errors;
}
}
CompanyController->index()
功能始终显示NULL
。为什么呢?
修改 我的会话设置是:
'driver' => 'native',
'lifetime' => 0,
'domain' => '.domain.com',
答案 0 :(得分:0)
恢复config/session.php
的默认设置值,解决了问题!
所以,现在,配置是:
'driver' => 'native',
'lifetime' => 0,
'domain' => null,