How passing variables from class to another php file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wooody
Forum Newbie
Posts: 1
Joined: Tue May 04, 2010 4:00 am

How passing variables from class to another php file

Post by wooody »

Hello all,


Im newbie with coding.. try to make thing in code.. i have this file

Helper.php and File.php



Helper.php

Code: Select all

class modMainMenuHelper 
{ 
    function buildXML($params) 
    { 
        $menu = new JMenuTree($params); 
        $items = &JSite::getMenu(); 

        // Get Menu Items 
        $rows = $items->getItems('menutype', $params->get('menutype')); 
        $maxdepth = $params->get('maxdepth',10); 

        // Build Menu Tree root down (orphan proof - child might have lower id than parent) 
        $user =& JFactory::getUser(); 
        $ids = array(); 
        $ids[0] = true; 
        $last = null; 
        $unresolved = array(); 
        // pop the first item until the array is empty if there is any item 
        if ( is_array($rows)) { 
            while (count($rows) && !is_null($row = array_shift($rows))) 
            { 
                if (array_key_exists($row->parent, $ids)) { 
                    $row->ionly = $params->get('menu_images_link'); 
                    $menu->addNode($params, $row); 

                    // record loaded parents 
                    $ids[$row->id] = true; 
                } else { 
                    // no parent yet so push item to back of list 
                    // SAM: But if the key isn't in the list and we dont _add_ this is infinite, so check the unresolved queue 
                    if(!array_key_exists($row->id, $unresolved) || $unresolved[$row->id] < $maxdepth) { 
                        array_push($rows, $row); 
                        // so let us do max $maxdepth passes 
                        // TODO: Put a time check in this loop in case we get too close to the PHP timeout 
                        if(!isset($unresolved[$row->id])) $unresolved[$row->id] = 1; 
                        else $unresolved[$row->id]++; 
                    } 
                } 
            } 
        } 
         
        //Woody New Modification Load CSS and JS 
        $document    = &JFactory::getDocument(); 
        $document->addStyleSheet(JURI::base() . "modules/mod_mainmenu/css/menu.css"); 
            $document->addScript(JURI::base() . "modules/mod_mainmenu/css/menu.js"); 
         
         
        return $menu->toXML(); 
    } 

    function &getXML($type, &$params, $decorator) 
    { 
        static $xmls; 

        if (!isset($xmls[$type])) { 
            $cache =& JFactory::getCache('mod_mainmenu'); 
            $string = $cache->call(array('modMainMenuHelper', 'buildXML'), $params); 
            $xmls[$type] = $string; 
        } 

        // Get document 
        $xml = JFactory::getXMLParser('Simple'); 
        $xml->loadString($xmls[$type]); 
        $doc = &$xml->document; 

        $menu    = &JSite::getMenu(); 
        $active    = $menu->getActive(); 
        $start    = $params->get('startLevel'); 
        $end    = $params->get('endLevel'); 
        $sChild    = $params->get('showAllChildren'); 
        $path    = array(); 

        // Get subtree 
        if ($start) 
        { 
            $found = false; 
            $root = true; 
            if(!isset($active)){ 
                $doc = false; 
            } 
            else{ 
                $path = $active->tree; 
                for ($i=0,$n=count($path);$i<$n;$i++) 
                { 
                    foreach ($doc->children() as $child) 
                    { 
                        if ($child->attributes('id') == $path[$i]) { 
                            $doc = &$child->ul[0]; 
                            $root = false; 
                            break; 
                        } 
                    } 

                    if ($i == $start-1) { 
                        $found = true; 
                        break; 
                    } 
                } 
                if ((!is_a($doc, 'JSimpleXMLElement')) || (!$found) || ($root)) { 
                    $doc = false; 
                } 
            } 
        } 

        if ($doc && is_callable($decorator)) { 
            $doc->map($decorator, array('end'=>$end, 'children'=>$sChild)); 
        } 


    
       $tag_id =  $params->get('tag_id'); 

        return $doc; 
    } 


File.php

Code: Select all

 
<script type="text/javascript"> 
var menuidsx=["leftmenu1"] 
</script> 



My question.. how can i make the Leftmenu1 in menuidsx var load from
helper.php file .. from this var $Tag_id in getXML function

thanks .
Post Reply