Làm thế nào bạn nhận được param sorta tùy thuộc vào vị trí của bạn,
Bạn không phải bắt yêu cầu $ param để đạt được những gì bạn muốn làm ở đây. Bạn chỉ đang sử dụng trình trợ giúp FlashMessenger để thêm thư vào ngăn xếp. Sau đó, bạn truy xuất thông báo trong hành động mà bạn muốn hiển thị thông báo, sau đó gán nó cho chế độ xem như tôi làm trong successAction. Hãy nhớ rằng bạn có thể truyền bất kỳ $ var hoặc mảng dữ liệu nào bằng cách gán nó trong bộ điều khiển như: $ this-> view-> var = $ var; Trong khung nhìn mà sau đó sẽ được truy cập dưới dạng $ this-> var.
Vì bạn đã hỏi về thông tin đăng nhập, tôi sẽ chỉ cho bạn cách tôi thường làm điều đó. Không phải đó là cách tốt nhất.
xem chỉ số của tôi LoginController của tổ chức dưới hình thức:
public function indexAction() {
$form = new Zfcms_Form_Login;
$this->view->form = $form;
/*check for valid input
authenticate using adapter
persist user record to session
redirect to original request URL if present*/
if ($this->getRequest()->isPost()) {
if ($form->isValid($this->getRequest()->getPost())) {
$values = $form->getValues();
$authAdapter = $this->getAuthAdapter();
# get the username and password from the form
$username = $values['username'];
$password = $values['password'];
# pass to the adapter the submitted username and password
$authAdapter->setIdentity($username)
->setCredential($password);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
# all info about this user from the login table
# ommit only the password, we don't need that
$userInfo = $authAdapter->getResultRowObject(null, 'password');
# the default storage is a session with namespace Zend_Auth
$authStorage = $auth->getStorage();
$authStorage->write($userInfo);
$session = new Zend_Session_Namespace('zfcms.auth');
if (isset($session->requestURL)) {
$url = $session->requestURL;
unset($session->requestURL);
$this->_redirect($url);
} else {
$this->_helper->getHelper('FlashMessenger')
->addMessage('You were successfully logged in as ' . $userInfo->username);
$this->_redirect('/login/success');
}
} else {
$this->view->message = 'You could not be logged in. Please try again.';
}
}
}
}
Trong hành động thành công, chúng tôi làm điều này:
public function successAction() {
if ($this->_helper->getHelper('FlashMessenger')->getMessages()) {
$this->view->messages = $this->_helper
->getHelper('FlashMessenger')
->getMessages();
} else {
$this->_redirect('/login/success');
}
}
Trong kịch bản xem chúng ta có thể làm điều gì đó giống như những gì tôi có dưới đây. Lý do tôi làm theo cách này là đôi khi tôi sẽ vượt qua chỉ là một tin nhắn duy nhất trong một bộ điều khiển, trong trường hợp này tôi chỉ cần sử dụng:
$this->view->message = 'message goes here';
Sau đó, bắt họ cả hai nếu họ được thiết lập trong giao diện:
<?php
if(isset($this->message) || isset($this->messages)):
?>
<?php
if(is_array($this->messages))
{
echo implode($this->messages);
} else {
echo $this->message;
}?>
<?php
endif
?>
Làm thế nào để bạn truy xuất thông số $ khi bạn đến đó? –