2009年4月1日星期三

[fw-mvc] Access the name of the controller from a View_Helper script.

I would like to access the name of the controller from a View_Helper script.

I think I could figure out how to explicitly pass it to the view, but I don't want to have to do this in every Controller.

Any comments regarding how to generate navigation in the layout script based on which controller is being called are welcome as well. Especially if I am not going about it the best way. See code below.

Thanks!

<?php

class Zend_View_Helper_Nav extends Zend_View_Helper_Abstract {
   
    /* Return appropriate navigation based on controller */
    public function nav() {
       
        $controller = ????????????????????????
       
        if ( $controller != 'admin' ) {
            $nav = file_get_contents(dirname(__FILE__). '/defaultNav.php');
        } else {
            $nav = file_get_contents(dirname(__FILE__). '/adminNav.php');
        }
        return $nav;
    }
   
}

没有评论: