Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1038239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:57:02+00:00 2026-05-16T14:57:02+00:00

Okay. I’m building a CMS with Zend. It isn’t as simple as it looked

  • 0

Okay. I’m building a CMS with Zend. It isn’t as simple as it looked but still — the best solution for me. I have a tree system with ID and PARENT, PARENT marks under which page the child resides. Anyway. Simple stuff.

Every time a page is created or sorted Nav & Routes are regenerated.

I’ll copy the whole Admin_Pages_Model code for creating Navigation and Routes here.

Navigation is created here:
(I think that module/controller/action information isn’t needed because it is loaded from router)

    public function createNavigation($locale = false){  
    $root = $this->getRoot($locale);

    $navigation = array();
    $router = array();

    foreach($root as $row){

        $navigation[$row["id"]] = array(
            "label" => $row["name"],
            "module" => "frontend",
            "controller" => "page",
            "action" => "show",
            "route" => "route_".$row["id"],
            "visible" => (boolean) $row["active"],
            "lastmod" => ($row["modified"] ? $row["modified"] : $row["created"])
        );

        $children = $this->getChildren($row["id"]);

        if(count($children)){
            foreach($children as $child){

                $navigation[$row["id"]]["pages"][$child["id"]] = $this->_createNavigation($child["id"]);

            }
        }

    }

    $nav = new Zend_Navigation(new Zend_Config($navigation));

    $this->createRoutes();

    if(!$locale){
        Crcms_Config::setConfig("navigation_sitemap", $nav->toArray());
    } else {
        Crcms_Config::setConfig("navigation_".$locale, $nav->toArray());
    }
}
private function _createNavigation($id){
    $page = $this->getPage($id);

    $navigation = array(
        "label" => $page["name"],
        "module" => "frontend",
        "controller" => "page",
        "action" => "show",
        "route" => "route_".$page["id"],
        "visible" => (boolean) $page["active"],
        "lastmod" => ($page["modified"] ? $page["modified"] : $page["created"])
    );

    $children = $this->getChildren($page["id"]);

    if(count($children)){
        foreach($children as $child){

            $navigation["pages"][$child["id"]] = $this->_createNavigation($child["id"]);

        }
    }

    return $navigation;
}

In the end – before saving navigation to database it calls $this->createRoutes(); So heres the code:

    public function createRoutes(){
    $root = $this->getRoot($locale);

    foreach($root as $row){

        $slugPath = "/".$row["slug"]."";

        $router["route_".$row["id"]] = array(
            "route" => $slugPath.".html",
            "defaults" => array(
                "pageId" => $row["id"],
                "locale" => $row["locale"],
                "module" => "frontend",
                "controller" => "page",
                "action" => "show"
            )
        );

        $children = $this->getChildren($row["id"]);

        if(count($children)){
            foreach($children as $child){

                $router = array_merge($router, $this->_createRoutes($child["id"], $slugPath."/".$child["slug"].""));

            }
        }
    }

    $routerConfig = new Zend_Config($router);

    Crcms_Config::setConfig("frontend_router", $routerConfig->toArray());

}
private function _createRoutes($id, $slugPath){
    $page = $this->getPage($id);

    $router["route_".$page["id"]] = array(
        "route" => $slugPath.".html",
        "defaults" => array(
            "pageId" => $page["id"],
            "locale" => $page["locale"],
            "module" => "frontend",
            "controller" => "page",
            "action" => "show"
        )
    );

    $children = $this->getChildren($page["id"]);

    if(count($children)){
        foreach($children as $child){
            $router = array_merge($router, $this->_createRoutes($child["id"], $slugPath."/".$child["slug"].""));
        }
    }

    return $router;
}

So now everything is database.
In my boostrap I load:

    protected function _initPostFrontController(){
    $this->bootstrap('frontController');

    $front = $this->getResource("FrontController");

    $frontendRouterConfig = new Zend_Config(Crcms_Config::getConfig("frontend_router"));

    $router = $front->getRouter();
    $router->addConfig($frontendRouterConfig);

    $front
        ->setParam("prefixDefaultModule", true)
        ->registerPlugin(new Global_Setup())
        ->registerPlugin(new Global_Auth())
        ->registerPlugin(new Global_Translation())
        ->registerPlugin(new Global_LayoutLoader());
}

This is my Global_Setup:

class Global_Setup extends Zend_Controller_Plugin_Abstract {
public function preDispatch (Zend_Controller_Request_Abstract $request){

    $front = Zend_Controller_Front::getInstance();

    $errorHandler = $front->getPlugin("Zend_Controller_Plugin_ErrorHandler");
    $errorHandler->setErrorHandlerModule("frontend");

    $layout = Zend_Layout::getMvcInstance();
    $view = $layout->getView();

    switch($request->getModuleName()){
        case "admin":
            $session = new Zend_Session_Namespace("Crcms_Admin");

            $locale = Zend_Registry::get("Zend_Locale");
            $view->doctype("HTML5");        
            $view->headTitle(Zend_Registry::get("Zend_Config")->system->about->software);
            $view->headTitle()->setSeparator(" | ");
            $view->headTitle(Crcms_Config::getConfig("site_name"));
            $view->headLink()->headLink(array(
                "rel" => "shortcut icon",
                "href" => Zend_Registry::get("Zend_Config")->system->paths->http->publib."/images/favicon.ico"), "PREPEND");    
        break;
        default:
            $session = new Zend_Session_Namespace("Crcms_Frontend");

            if(!$session->locale){
                $session->locale = Crcms_Config::getConfig("locale_default");
            }

            $navigation = new Zend_Navigation(new Zend_Config(Crcms_Config::getConfig("navigation_".$session->locale)));
            $view->navigation()->setContainer($navigation);

        break;
    }

}

}

So basically everything is Okay. The LayoutLoader selects the default layout path and the layout based on admin/frontend.

Anyway. In my frontend layout I have this :

<div id="menu"><?= $this->navigation()->menu(); ?></div>
<div id="breadcrumb"><?= $this->navigation()->breadcrumbs(); ?></div>
<div id="content"><?= $this->layout()->content; ?></div>

The menu creates fine. All levels are super (Y). but EVERYTHING is class=”active”!!! and readcrumb always shows the most deepest element.

The page selection works fine! The param pageId is passed right and the router works. Navigation is messed up only.

Some pics to give you the idea:

The admin side:
– http://grab.by/6d67

The frontend side:

  • http://grab.by/6d5Y
  • http://grab.by/6d6e
  • http://grab.by/6d6g
  • http://grab.by/6d6h

So as seen from the pictures URL changes – content changes also. So router must work.

Everything is just “active”: http://grab.by/6d6j

I know that I’ve pasted alot of info here but please help me. I’ve like worked 20+ hours on this problem — no solution help.

Kinda fixed it. I don’t think it’s the “right way” but still – its now working. I commented controller/action/module out from the navigation thing (nothing has changed in Routes). Added a “id” => “page-“.$page[“id”].

Now in my Global_Setup I did something like this ->

$navigation = new Zend_Navigation(new Zend_Config(Crcms_Config::getConfig("navigation_".$session->locale)));
$navigation->findBy("id", "page-".$request->getParam("pageId"))
->setActive(true);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:57:03+00:00Added an answer on May 16, 2026 at 2:57 pm

    This is something of a guess, as it’s hard to work this out just by looking at the code.

    When you are building up your routes, you’re setting a pageId:

    $router["route_".$row["id"]] = array(
        "route" => $slugPath.".html",
        "defaults" => array(
            "pageId" => $row["id"],
            "locale" => $row["locale"],
            "module" => "frontend",
            "controller" => "page",
            "action" => "show"
        )
    );
    

    Presumably this is the unique identifier you use in your controller to work out which page was requested?

    Zend Navigation calls the isActive() method on each page to work out which one to highlight. For Mvc pages what this does is compare the route params you’ve supplied (controller, module, action and other params) to the params in the request object. In your case, all of the pages point at the same action, and you haven’t given Zend Navigation the pageId so all it’s doing is comparing module/controller/action to the module/controller/action in the request, which will always match.

    If I’m right, all you need to do is add the pageId to the navigation object you build up, so in the loop in your first code sample:

    $navigation[$row["id"]] = array(
        "label" => $row["name"],
        "module" => "frontend",
        "controller" => "page",
        "action" => "show",
        "route" => "route_".$row["id"],
        "params" => array("pageId" => $row["id"]), // this line is new!
        "visible" => (boolean) $row["active"],
        "lastmod" => ($row["modified"] ? $row["modified"] : $row["created"])
    );
    

    If this doesn’t work, I hope it will at least point you in the right direction. I do think the isActive() method is where the problem lies, so if you don’t mind debugging some Zend Framework code (temporarily), find that method in Zend/Navigation/Page/Mvc.php, verify that it is being called, and see if you can figure out where it’s going wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this question is very simple: I have a facebook page, and a website.
okay, i'm setting up a multi-user chat system. i have a messages table, that
Okay so my question is this. Say I have a simple C++ code: #include
Okay, I have setup up a handler for a div click but for some
Okay, basically I've developed a simple image upload system. The user selects a local
Okay so I have a simple HTML Input fragment: <input id=txtFirstName type=text class=txtBox runat=server
Okay i know i have to use the JDBC etc, but im not sure
Okay I got some good advice for Mobile Detection but still having an issue
Okay, I've looked all over the internet for a good solution to get PHP
Okay so im working on this php image upload system but for some reason

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.