开发者

How to make link in joomla

开发者 https://www.devze.com 2023-02-19 03:56 出处:网络
hi i am new in joomla.I need the dynamic link in view file. //no direct access defined(\'_JEXEC\') or die(\'Direct Access to this location is not allowed.\');

hi i am new in joomla.I need the dynamic link in view file.

//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?


change your this line from view file:

<a href="#"> echo JText::sprintf($item->name); </a>

to :

echo "<a href='".$item->link."'>". JText::sprintf($item->name)."</a>";

assuming, link is the field name of your link else change it according to the field name you've used for link. this may help, i guess .. good luck with it.


use

echo "<a href='".JRoute::_($item->link, false)."'>". JText::sprintf($item->name)."</a>";

JRoute will take care of routing also, if routing is enabled.

0

精彩评论

暂无评论...
验证码 换一张
取 消