Flash Messenger не отображает сообщения

Я только недавно начал работать над сайтом, который использует Zend Framework.
Флэш-сообщение на сайте не работает, и это моя работа, чтобы исправить это.
Я попытался выяснить, что с ним не так, и у меня был частичный успех в понимании кода.

Я никогда раньше не работал в Zend Framework, поэтому я не знаю, что можно сломать или даже как правильно его отладить.

Я попытался разместить код, который был предложен в этот вопрос но это просто сломало php в целом.

Буду очень признателен, если кто-нибудь сможет мне помочь с этим кодом:
Я включу файлы ниже:


LoginController.php, который расширяет MrBlue_Controller_Action_Default
и вызывает флэш-сообщение следующим образом:

{
$this->_flashMessenger->addMessage(array('success', 'Done. Now get your email and confirm you account'));
$this->redirect('/');
}

MrBlue_Controller_Action_Default расширяет Zend_Controller_Action

<?php

/**
* Default.php
*/
abstract class MrBlue_Controller_Action_Default extends Zend_Controller_Action
{

/**
* Zend_Acl
*
* @var Zend_Acl
* @access protected
*/
protected $_acl = null;

/**
* FlashMessenger
*
* @var object
* @access protected
*/
protected $_flashMessenger = null;

/**
* Array with params (controller, action, etc)
*
* @var array
* @access protected
*/
protected $params;

/**
* Application config object
*
* @var Zend_Config
* @access protected
*/
protected $config;

/**
* MrBlue Benchamark Helper
*
* @var MrBlue_Helper_Benchmark
* @access protected
*/
protected $benchmark;

/**
* Zend_Auth
*
* @var Zend_Auth
* @access protected
*/
protected $_auth = null;

/**
* User account
*
* @var object
* @access protected
*/
protected $account = null;

/**
* Array of post values
* @var array
*/
protected $aPost = array();

/**
* @var Zend_Session_Namespace
*/
protected $oDefaultUserNS = null;

/**
*  init()
*
* @access public
*/
public function init()
{
$this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->_flashMessenger->getMessages();

$this->params = $this->getAllParams();
$this->params['c/a'] = $this->params['controller'] . '/' . $this->params['action'];
$this->view->params = $this->params;

if ($this->_request->isPost())
{
$this->aPost = $this->_request->getPost();
}
$this->view->aPost = $this->aPost;

$this->config = Zend_Registry::get('config');
$this->view->config = $this->config;

// Zend ACL
$this->_acl = Zend_Registry::get('acl');
$this->view->acl = $this->_acl;
$this->view->role = 'guest';    // will be overwrite in setAccountData()//create navigation container
$this->prepareNavigation();

$this->oDefaultUserNS = new Zend_Session_Namespace('default_data');

$this->benchmark = new MrBlue_Helper_Benchmark();
//$this->view->benchmark = $this->benchmark;

$this->setAuth();
}

/**
* Prepare navigation container based on navigation.php file and
* dynamic pages from database
*/
public function prepareNavigation()
{
//get current role or if null default guest role with limited access
$role = 'guest';
if( Zend_Auth::getInstance()->hasIdentity() ) {
$role = Zend_Auth::getInstance()->getIdentity()->role;

/*
OLD CODE to display leaderboard menu based on leader_board flag in users table
*
*
//allow Leaderboard page if user have "List me on leader board" flag set to 1
//flag has to be check from database  - not from identity, because it can change in session
$user_app = new Model_UsersApp();
$user = $user_app->getById(Zend_Auth::getInstance()->getIdentity()->id);

if($user->leader_board == 1)
{
$this->_acl->allow('user', 'default:leaderboard', null);
}
else
{
$this->_acl->deny('user', 'default:leaderboard', null);
}
*
*/
}

/*
* NEW CODE - to display leaderboard menu item based on flag in settings table
*/
//allow Leaderboard page
//  $settings_app = new Model_SettingsApp();

if(MrBlue_Setting::get('leaderboard_menu')==1)
{
$this->_acl->allow('user', 'default:leaderboard', null);
}
else
{
$this->_acl->deny('user', 'default:leaderboard', null);
}//create navigation from navi file
$navConfig = require APPLICATION_PATH . '/modules/default/configs/navigation.php';
$navigation = new Zend_Navigation($navConfig);

//get dynamic pages
$pages_app = new Model_PagesApp();
$pages = $pages_app->getList(1);

//add dynamic pages to navigation
foreach ($pages as $page)
{
if( $page['roles']==Model_Db_PagesDb::ROLE_ALL || $page['roles']==$role ) {
$page_nav = new Zend_Navigation_Page_Mvc(array(
'route' => 'pages',
'module' => 'default',
'controller' => 'pages',
'action' => 'read',
'params' => array('pageslug' => $page['name_slug']),
'label' => $page['name'],
'position' => $page['position'],
'roles' => $page['roles']
));

$navigation->addPage($page_nav);
}
}

//send navigation to view container
$this->view->navigation($navigation)->setAcl($this->_acl)->setRole($role);
}

/**
* Set auth
*
* @access public
* @return void
*/
public function setAuth()
{
$this->_auth = Zend_Auth::getInstance();
$this->_auth->setStorage(new Zend_Auth_Storage_Session('Default_Auth'));

if ($this->_auth->hasIdentity())
{
$this->setAccountData();
}
else
{
if ($this->params['c/a'] != 'login/authorize')
{
//@TASK uncomment redirection for denied resources
// return $this->redirect('index/index');
}
}
}

/**
* Checking if some action in current module and controller is allowed
*
* @param string $action
* @return boolean
*/
public function isActionAllowed($action)
{
return $this->_acl->isAllowed($this->account->role, $this->_request->getModuleName() . ':' . $this->_request->getControllerName(), $action);
}

/**
* Set account data
*
* @access public
* @return void
*/
public function setAccountData()
{
if ($this->_auth->hasIdentity())
{
$this->account = $this->_auth->getIdentity();

$climbing_app = new Model_ClimbingApp();
$climbing = $climbing_app->getUserLastClimbing($this->account->id);
$this->account->climbing = $climbing;
//            $this->account->funds = $climbing['funds'];
//            $this->account->coins = $climbing['coins'];
unset($climbing_app);

//must be ass separate query because if user have no climbing records, there is nothing to join user table values
$user_app = new Model_UsersApp();
$user = $user_app->getById($this->account->id);

$this->account->funds = $user->funds;
$this->account->coins = $user->coins;

unset($user_app);

$this->view->account = $this->account;
$this->view->role = $this->account->role;

// Zend_Registry
Zend_Registry::set('account', $this->account);
Zend_Registry::set('auth', $this->_auth);
}
}

/**
* Get current climbing values
*
* @return array
*/
public function getUserClimbing()
{
$aClimbing = array();

if ( $this->_auth->hasIdentity() && isset($this->account->climbing) && !empty($this->account->climbing) )
{
$aClimbing = $this->account->climbing;
}

return $aClimbing;
}

}

index.php, где я хотел бы показать сообщение:

<section class="landing-main landing-main2">
<div class="landing-logo">
<!-- <h1>
Sports Ladder <br />
<span>Challenge</span>
</h1>
<div class="logo-star">
&#9733;
</div> -->
<img src="http://www.sportsladderchallenge.com/img/Logo.png" alt="Sports Ladder Challenge" />
</div>
<section class="main-highlight">

<div class="join-section-right">
<p class="cta-caption">
Win up to <span>$50,000.00</span>
</p>
<a class="cta" href="<?php echo $this->url(array('controller'=>'login','action'=>'register'),null,true); ?>" alt="" id="signup-button" />
Join Now <span>&raquo;</span>
</a>
<p class="cta-caption">
It's absolutely 100% <strong>free</strong>.
</p>

</div>
</section>

<section class="sports-ladder">
<?php if($this->double == 2) $d = true; else $d = false;
echo $this->partial('partials/ladder_sidebar.phtml',array('ladder' => $this->ladder,'safe_zones' => $this->ladder_safe,
'level' => $this->current_rung, 'double' => $d) );
?>

<br />
<?php
$oLadder = new Model_LadderObj();
if( !is_null($this->current_rung) && !in_array($this->current_rung,$oLadder->getSafeZones()) && $this->current_rung!=0 ) :
?>
<a class="header-buttons ladder-collect" href="<?php echo $this->url(array('action'=>'respawn-climbing'),null,true); ?>" class="btn btn-primary btn-collect" style="margin-left:16px; width:207px;" title="By pressing ‘collect’ you will have the specified dollar amount on any non-safe step (steps 5,6,8,9 etc) deposited into your account balance and forfeit the remainder of your climb. This action cannot be undone.">Collect</a>
<?php else : ?>
<a class="header-buttons ladder-collect" href="javascript:return false;" class="btn btn-default btn-collect" style="margin-left:16px; width:207px;" title="By pressing ‘collect’ you will have the specified dollar amount on any non-safe step (steps 5,6,8,9 etc) deposited into your account balance and forfeit the remainder of your climb. This action cannot be undone.">Collect</a>
<?php endif; ?>
</section>

<section class="main-htp">
<h2>
How To Play
</h2>
<h4>
And win up to <span>$50,000.00</span>!
</h4>
<div class="htp">
<div class="htp-number">
1
</div>
<h3>Sign Up</h3>

<li>
Sign up, it's completely free to play!
</li>
<li>
Pick one of our sports match ups
</li></div>
<div class="htp">
<div class="htp-number">
2
</div>
<h3>Build Your Streak</h3>
<li>
Make a right pick, and climb a step
</li>
<li>
The higher you climb, the more money you win!
</li>

</div>
<div class="htp">
<div class="htp-number">
3
</div>
<h3>Cash Out</h3>
<li>
Earn anywhere from $0.01 to $50,000.00 per climb
</li>
<li>
Increase your account balance to $100 or more and cash out, it's that easy!
</li>

</div>
</section>

<section class="main-bottom-left">
<h2>Start Playing Today</h2>
<div class="join-section-left">
<div class="join-section">
<p class="star">&#10097;</p>
<p>
The Sports Ladder Challenge combines the use of power ups, a wider selection of games and questions to choose from, as well as an innovative new platform that is optimized to reward users on a variety of levels to combine for the most thrilling, action packed pick em game on the web!
</p>

</div>

<div class="join-section">
<p class="star">&#10097;</p>
<p>
We cover a wide variety of sports and leagues including the NFL, NBA, MLB, NHL, Premier League, La Liga and much more!
</p>

</div>
<div class="join-section">
<p class="star">&#10097;</p>
<p>
There is no limit to how much you can win! Win anywhere from $0.01 to $50,000.00 on every climb. We GUARANTEE that with enough sports knowledge and due diligence, you will cash out!
</p>

</div>
</div>

</section>
</section>

_flash_messenger.phtml частичный

<?php if ( !empty($this->messages) ): ?>
<div style="margin-left:auto;margin-right:auto;width:90%;">
<?php foreach($this->messages as $message): ?>
<?php if($message[0] == 'error'): ?>
<div class="alert alert-block alert-danger">
<?php elseif($message[0] == 'success'): ?>
<div class="alert alert-block alert-success">
<?php endif; ?>
<p><strong><?php echo $message[1]; ?></strong></p>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>

Я бы очень признателен за любую помощь, которую я могу получить.
Если эта информация неполная, пожалуйста, дайте мне знать, и я опубликую дополнительные фрагменты кода.

Обновить Полный код для LoginController.php
Ссылка на сайт: http://codepad.org/VL4DGLtX

0

Решение

Похоже, сообщения не отображаются.

Если вы посмотрите на предоставленный вами абстрактный контроллер, то вот этот код:

$this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->_flashMessenger->getMessages();

Это захватывает помощник действия флэш-мессенджера (доктор) и поместить все сообщения в представление (шаблон).

Теперь вам нужно визуализировать частичный шаблон _flash_messenger.phtml в месте, где вы хотите эти сообщения. Для этого вы можете использовать частичный помощник вида (доктор):

<?php echo $this->partial('path/to/_flash_messenger.phtml', array('messages' => $this->messages)); ?>
1

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]