douchan7552 2015-01-22 07:28
浏览 47

flash messenger不显示消息

I just recently started working on a website that uses Zend Framework. The flash message on the website is broken and it is my job to fix it. I have tried figuring out what is wrong with it and I had partial success with understanding the code.

I never worked in Zend Framework before so I am not familiar with what can be broken or even how to debug it correctly.

I have tried placing the code that was suggested in this question but it simply broke the php altogether.

I would really appreciate if somebody could help me out with this code: I will include files below:


LoginController.php which extends MrBlue_Controller_Action_Default and calls flash msg in the following manner:

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

MrBlue_Controller_Action_Default extends 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 where i'd like to display the msg:

<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 partial

<?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; ?>

I'd really appreciate any help i can get. If this information is incomplete please let me know and i will post the additional code snippets.

Update Full Code for LoginController.php Link: http://codepad.org/VL4DGLtX

  • 写回答

1条回答 默认 最新

  • dongrouyuan5685 2015-01-22 08:30
    关注

    It looks like messages are no rendered.

    If you look at the abstract controller you provided, there is this code:

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

    This grabs the flash messenger action helper (doc) and put all the messages into the view (template).

    Now you need to render the partial template _flash_messenger.phtml in place where you want those messages. For this, you can use partial view helper (doc):

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

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大