Jmodel populateState documentation

239 views
Skip to first unread message

Liam

unread,
May 21, 2012, 7:13:53 PM5/21/12
to Joomla! General Development
Anybody have any documentation, been searching for hours on google etc
and couldn't find anything.

I just want to achieve how the publish/unpublish, trash, archive etc
work, looking at the other components I have copied what they do what
I can never get the DB to update the state/published coloumn.

I also noticed that each component seems to use state or published,
but not sure which one is right for my component.

It is a simple list of data and just want an idea of how the state
works and how I can implement within my component. Perhaps I am
googling the wrong words but I can't seem to find the documentation on
how to use it, I can find the api reference but no examples.

Any help much appreciated.

JSamir

unread,
May 22, 2012, 3:38:04 AM5/22/12
to joomla-de...@googlegroups.com
Hi,

as far as i know, you dont need the populatestate method for what you want to achieve.

I can't look for the code right now, but i'll tell you how i found out where the code is in the core components:

1. Go in backend of some core component and look at the list, find the button for publish/unpublish and look at the code, you are gonna find a string similiar to this "controllername.task", for example articles.unpublish (i dont know if this one exists, just an example). 

2. Now you know thich controller to search for. Go to this controller and look for that method, if you dont find it, look in the inherited classes.

3. Rest should be similar.

Hope it helps

Liam

unread,
May 22, 2012, 4:31:52 AM5/22/12
to Joomla! General Development
Thanks, re-read another component this morning and got it working. It
was my left join in the query causing an issue, for some reason the ID
number of the table gets replaced by the ID number of the other table.

Here is what my get list query looks like:
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
// From the obituaries people table
$query->from('#__obituaries_comments AS a');

// Filter by published state.
$published = $this->getState('filter.state');
if (is_numeric($published)) {
$query->where('a.published = '.(int) $published);
}
elseif ($published === '') {
$query->where('(a.published IN (0, 1))');
}

// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$query->where('a.id = '.(int) substr($search, 3));
} else {
$search = $db->Quote('%'.$db->escape($search, true).'%');
$query->where('(a.commentername LIKE '.$search.' OR b.lastname
LIKE '.$search.' OR b.firstname LIKE '.$search.' OR a.commenteremail
LIKE '.$search.')');
}
}

// Join over the categories.
$query->select('CONCAT(b.firstname,\' \',b.lastname) AS
obituary_name');
$query->join('LEFT', '#__obituaries_people AS b ON b.id =
a.obituaryid');

// Add the list ordering clause.
$orderCol = 'a.datecreated';
$orderDirn = 'desc';
$query->order($orderCol.' '.$orderDirn);

return $query;
}

The end result works I retrive the name fine from the people table
however when I place $this->items and cycle through the ID for the
comments table is overwritten by the people table, is strange. When
doing a print_r() it looks like the left join is pulling all data from
the people table, when I only need 3 coloumns, so I guess this is why
ID is overwritten.

I am new to queries and still learning how the joins work, I have the
understanding a left join is what I need to match the id numbers and
then retrive the persons name.

I hope it makes sense and if you can see anything wrong with my query
I would appreciate any help you can offer.

Many thanks.

Liam

unread,
May 22, 2012, 4:58:26 AM5/22/12
to Joomla! General Development
Ok worked it out for anybody starting out like myself, I was lazy and
just put a * in the first select statement. This then pulling in the
second tables id coloumn which then as it was loaded second overwrote
when calling on the template ($this->items etc).

I found to overcome this problem I need to specify the coloumns I want
which was all for the first table, but only first name and last name
on the second table, this then only pulls in the name and no ID nmber
and in turn not overwriting your original ID number.

Hope that helps someone. Thanks JSamir for pointing me in the right
direction.
Reply all
Reply to author
Forward
0 new messages