嗨,我是joomla的新手。我需要视图文件中的动态链接。
//no direct access defined('_JEXEC') or die('Direct Access to this location is not allowed.');
// include the helper file require_once(dirname(FILE).DS.'helper.php');
// get a parameter from the module's configuration
$userCount = 5;
// get the items to display from the helper $items = ModNewHelper::getItems($userCount);
//link of the component
// include the template for display require(JModuleHelper::getLayoutPath('mod_new'));
this is main file
/** * @author Raju Gautam * @copyright 2011 */
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
class ModNewHelper { /** * Returns a list of post items */ public function getItems($userCount) { // get a reference to the database $db = &JFactory::getDBO();
// get a list of $userCount randomly ordered users $query = 'SELECT name,id FROM `#__hello` ORDER BY ordering LIMIT ' . $userCount . ''; $db->setQuery($query); $items = ($items = $db->loadObjectList())?$items:array(); return $items; } //end getItems
} //end ModHelloWorld2Helper
this is helper file
defined('JEXEC') or die('Restricted access'); // no direct access echo JText::('Latest News'); //echo "
"; print_r($items); exit;foreach ($items as $item) {
<a href="#"> echo JText::sprintf($item->name); </a>
} this is view file
I need the link on echo JText::sprintf($item->name); this line. can i helped please?
答案 0 :(得分:1)
从视图文件中更改此行:
<a href="#"> echo JText::sprintf($item->name); </a>
到:
echo "<a href='".$item->link."'>". JText::sprintf($item->name)."</a>";
假设,link
是您的链接的字段名称,否则根据您用于链接的字段名称进行更改。这可能会有所帮助,我想......祝你好运。
答案 1 :(得分:0)
使用
echo "<a href='".JRoute::_($item->link, false)."'>". JText::sprintf($item->name)."</a>";
JRoute
也会处理路由。