Login +

How To ? / Using Statics Controller

Suppose you want to build the menu of your site and dynamically manage the hover of the current item.

Your menu consists of a "Home" link, a Blog section and a page from the database.

Controller Statics "Menu.controller.php":

public function constructXML()
{
    $this->_generic->useModel("Page");
    $page = new Main_Page();
    
    $this->_xmlToolBox->startTag("item");
        $this->_xmlToolBox->addFullTag("title","Home",true);
        $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath("Home","Index"),true);
        $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId("Home","Index")) ? "true" : "false",true);
    $this->_xmlToolBox->endTag("item");
    $this->_xmlToolBox->startTag("item");
        $this->_xmlToolBox->addFullTag("title","Blog",true);
        $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath("Blog","Home"),true);
        $this->_xmlToolBox->addFullTag("selected",($this->_generic->getGenericControllerName() == "Blog") ? "true" : "false",true);
    $this->_xmlToolBox->endTag("item");
    if ($page->getModel(1))
    {
        $this->_xmlToolBox->startTag("item");
            $this->_xmlToolBox->addFullTag("title",$page->__get("page_title"),true);
            $this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath("Static","Page",array(array("key"=>"Id","value"=>$page->__get("page_id")))),true);
            $this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId("Static","Page") && $this->_http->getParam("Id") == $page->__get("page_id")) ? "true" : "false",true);
        $this->_xmlToolBox->endTag("item");
    }
}

The first technique is to check if the current Action corresponds to Action Home/Index.

The second technique is to check if the current Controller is the Controller Blog, since we want to hover on the blog for all the Actions of Blog Controller (Home, Article, Comment, etc.)

The third technique is based on the Id of the article and the recovery of a GET parameter.

Template __default.xsl:

<ul class="header">
    <xsl:for-each select="//Statics/Site/Menu/item">
        <li>
            <a href="{href}" title="{title}">
                <xsl:if test="selected = 'true'"><xsl:attribute name="class">hover</xsl:attribute></xsl:if>
                <xsl:value-of select="title" />
            </a>
        </li>
    </xsl:for-each>
</ul>