I am new to Joomla, I am writing a script under folder cli. I am calling helper file of admin component where I fetch category and return url of category.
The function in helper is fine and works well when executed through admin menu.
The issue is with category URL not being generated when used in cli script.
$app = JApplication::getInstance('site');
$router = &$app->getRouter();
$newUrl = ContentHelperRoute::getCategoryRoute('10');
$newUrl = $router->build($newUrl);
$url = $newUrl->toString();
$url = str_replace('/administrator', '', $url);
when used with CLI it throws error for strict standards for $router = &$app->getRouter();
i have also tried
JRoute::_(ContentHelperRoute::getCategoryRoute('10'));
It just throws error saying failed to start application.
I want to get SEF url of category so that I can also get it returned in my cli file.
My cli code:
class Abc extends JApplicationCli
{
public function doExecute()
{
JFactory::getSession()->gc();
JLoader::register('AbcHelper',JPATH_BASE.'/administrator/components/com_abc/helper.php');
$url = AbcHelper::getUrl();
echo $url;
}
}
JApplicationCli::getInstance('Abc')->execute();
helper.php
public static function getUrl()
{
$url='';
$app = JApplication::getInstance('site');
$router = &$app->getRouter();
$newUrl = ContentHelperRoute::getCategoryRoute('10');
$newUrl = $router->build($newUrl);
$url = $newUrl->toString();
$url = str_replace('/administrator', '', $url);
return $url;
}
Any help is appreciated.