Getting article Alias

186 views
Skip to first unread message

Christian McCabe

unread,
Jun 5, 2013, 2:26:33 AM6/5/13
to joomla-de...@googlegroups.com
I am trying to populate a form field with the current article title:

i first tried: 
//<code>
$doc = JFactory::getDocument();
return $doc->getTitle();
//</code>
that only return the page title and because my article is linked to a menu it doesn't give the full article title

then i tried:

//<code>
$article = JTable::getInstance("content");
return $article->get("title");
//</code>
but this doesn't return any result
not sure if the syntax is correct

Can anyone point me in the right direction? Thanks
 

--

Kind Regards,

Christian McCabe

Viper

unread,
Jun 5, 2013, 2:49:31 AM6/5/13
to joomla-de...@googlegroups.com
JTable doesn't return any rows because you trying to get a title for all rows in table, but you need one row.

If you using JModelForm you can define getItem() and in this method you can get all article columns with simple sql query.
Something like this:
public function getForm($data = array(), $loadData = true) {
    $form = $this->loadForm('com_component.formname', 'formname', array('control' => 'form', 'load_data' => $loadData));

    if (empty($form)) {
        return false;
    }

    return $form;
}

protected function loadFormData() {
    return $this->getItem();
}

public function getItem() {
    $app = JFactory::getApplication();
    $db = $this->getDBO();
    $title = $this->getTitle(); // A way to get the article title(for example)

    $db->setQuery("SELECT `id`, `alias`"
        . "\n FROM ".$db->quoteName('#__content')
        . "\n WHERE `title` = '".$title."' AND `language` IN (".$db->quote(JFactory::getLanguage()->getTag()).','.$db->quote('*').")");
    $result = $db->loadObject();

    return $result;
}


You can get current menu via(of cause for frontend, not backend):
$app = JFactory::getApplication();
$menus = $app->getMenu();
$menu = $menus->getActive();

Christian McCabe

unread,
Jun 5, 2013, 2:53:45 AM6/5/13
to joomla-de...@googlegroups.com
this helped alot! thanks VIPER


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages