ksduded Posted January 18, 2010 Share Posted January 18, 2010 I am trying to use the return value from a function, but I don't know how to save it inside a variable. I tried this $j = return array_slice($rows, 0, $items); but it didn't work Right at the end of the code is return array_slice($rows, 0, $items); Is this value being saved inside a variable in the code provided? if not, how can I save it? The code is defined('_JEXEC') or die('Restricted access'); require_once (JPATH_SITE . '/components/com_content/helpers/route.php'); class modYOOcarouselHelper { function renderItem(&$item, &$params, &$access) { global $mainframe; $user =& JFactory::getUser(); $item->text = $item->introtext; $item->groups = ''; $item->readmore = (trim($item->fulltext) != ''); $item->metadesc = ''; $item->metakey = ''; $item->access = ''; $item->created = ''; $item->modified = ''; if ($params->get('readmore')) { // Check to see if the user has access to view the full article if ($item->access <= $user->get('aid', 0)) { $linkOn = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug, $item->sectionid)); } else { $linkOn = JRoute::_('index.php?option=com_user&task=register'); } $item->linkOn = $linkOn; } require(JModuleHelper::getLayoutPath('mod_yoo_carousel', '_item')); } function getList(&$params, &$access) { global $mainframe; $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $aid = $user->get('aid', 0); $catid = (int) $params->get('catid', 0); $items = (int) $params->get('items', 0); $order = $params->get('order', 'o_asc'); $contentConfig = &JComponentHelper::getParams( 'com_content' ); $noauth = !$contentConfig->get('shownoauth'); $nullDate = $db->getNullDate(); jimport('joomla.utilities.date'); $date = new JDate(); $now = $date->toMySQL(); // Ordering switch ($order) { case 'm_dsc': $ordering = 'a.modified DESC, a.created DESC'; break; case 'h_dsc': $ordering = 'a.hits DESC, a.created DESC'; break; case 'c_dsc': $ordering = 'a.created DESC'; break; case 'o_asc': default: $ordering = 'a.ordering'; break; } // Query to determine article count $query = 'SELECT a.*,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'. ' CASE WHEN CHAR_LENGTH(cc.name) THEN CONCAT_WS(":", cc.id, cc.name) ELSE cc.id END as catslug'. ' FROM #__content AS a' . ' INNER JOIN #__categories AS cc ON cc.id = a.catid' . ' INNER JOIN #__sections AS s ON s.id = a.sectionid' . ' WHERE a.state = 1 ' . ($noauth ? ' AND a.access <= ' .(int) $aid. ' AND cc.access <= ' .(int) $aid. ' AND s.access <= ' .(int) $aid : ''). ' AND (a.publish_up = "'.$nullDate.'" OR a.publish_up <= "'.$now.'" ) ' . ' AND (a.publish_down = "'.$nullDate.'" OR a.publish_down >= "'.$now.'" )' . ' AND cc.id = '. $catid . ' AND cc.section = s.id' . ' AND cc.published = 1' . ' AND s.published = 1' . ' ORDER BY ' . $ordering; $db->setQuery($query); $rows = $db->loadObjectList(); if ($order == 'rnd') shuffle($rows); return array_slice($rows, 0, $items); } } Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 $j = array_slice(...); is the correct way to assign a return from a function.. as this is a class, some more info is needed.. Are you calling this getList function from OUTSIDE the class or calling it at all? What is your intended use of that function? Quote Link to comment Share on other sites More sharing options...
ksduded Posted January 18, 2010 Author Share Posted January 18, 2010 Are you calling this getList function from OUTSIDE the class or calling it at all? What is your intended use of that function? it is being called from another file through this code $list = modYOOcarouselHelper::getList($params, $access); Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 19, 2010 Share Posted January 19, 2010 In that case $list IS the return value of that function.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.