Alerter
클래스의 인스턴스를 내 컨트롤러에서 세션이있는보기로 전달하려고합니다.
이것이 가능한가요, 어떻게 구현할 수 있습니까? 순간 컨트롤러에서 개체를 세션에 전달하는 방법은 무엇입니까?
Symfony \ Component \ Debug \ Exception \ FatalErrorException
main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Alerter" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition
:
<?php
use Acme\Repositories\Authority\Session\SessionInterface;
class Alerter {
protected $type;
protected $message;
function __construct($message, $type = 'warning')
{
$this->message = $message;
$this->type = $type;
}
public function setMessage($message)
{
$this->message = $message;
}
public function getMessage()
{
return $this->message;
}
public function setType($type)
{
$this->type = $type;
}
public function getType()
{
return $this->type;
}
}
/**
* Class SessionsController
*/
class SessionsController extends BaseController {
/**
* @var Acme\Repositories\Authority\Session\SessionInterface
*/
protected $session;
/**
* Inject SentrySession Dependency.
*
* @param SessionInterface $session
*/
function __construct(SessionInterface $session)
{
$this->session = $session;
}
/**
* Logout the user.
*
* @return \Acme\Repositories\Authority\Session\Response
*/
public function logout()
{
$this->session->destroy();
$alerter = new Alerter('Hello', 'success');
return Redirect::to('login')->with('alert', $alerter);
}
}
그리고 내보기는 다음과 같습니다
@if (Session::has('alert'))
<div class="alert alert-warning">
{{ Session::get('alert')->getMessage() }}
</div>
@endif
감사합니다 너의 도움으로!
역 직렬화와 관련하여 몇 가지 문제가있는 것으로 보입니다. 이것은 세션으로하지 말아야 할 일로 나를 공격합니다. 세션은 직렬화가 가능해야합니다 (문자열로 저장 됨). – Halcyon
어쩌면 당신은 맞다, 그러나 시도 가치가있다 :) – intelis