×
Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues
front end component view
Matthew
Yeni Üye
Posts: 12
9 yıl 7 ay önce #789
Yazan: Matthew
front end component view, Matthew tarafından oluşturuldu
Hi,
I would like users on the front end to only view their own created data - is that possible to limit via the component creator or do I have to edit the model?
Thanks,
Mat
I would like users on the front end to only view their own created data - is that possible to limit via the component creator or do I have to edit the model?
Thanks,
Mat
Lütfen sohbete katılmak için Giriş ya da Hesap açın.
Randy Carey
Bakır Üye
Posts: 23
9 yıl 7 ay önce - 9 yıl 7 ay önce #794
Yazan: Randy Carey
Randy Carey tarafından front end component view konusunda yanıtlandı
You can edit/override the component's template to accomplish this. Use a line of code like thisto evaluate each item within the foreach loop. if this is condition is false, do not process the code that displays the item.
A very concise piece of code that accomplishes this isand this would be placed at the start of the foreach loop. If the user is not the same as the user who created the item, the continue skips further processing of this item and the foreach continues with the next item.
$belongs_to_user = JFactory::getUser()->id == $item->created_by;
A very concise piece of code that accomplishes this is
if(! JFactory::getUser()->id == $item->created_by){
continue;
}
Son Düzenleme: 9 yıl 7 ay önce Düzenleyen:Randy Carey
Şu kullanıcı(lar) Teşekkür etti: Matthew
Lütfen sohbete katılmak için Giriş ya da Hesap açın.
Eduardo Mena
Bakır Üye
Posts: 31
9 yıl 7 ay önce - 9 yıl 7 ay önce #816
Yazan: Eduardo Mena
Eduardo Mena tarafından front end component view konusunda yanıtlandı
Randy's answer will work
But it's cleaner if you do it from the model.
Go to /components/com_YOUR_COMPONENT/models/EXAMPLE.php
Look for the getListQuery() method and then look for this
And change to thisUsers that are not allowed to edit state will only see their own items
But it's cleaner if you do it from the model.
Go to /components/com_YOUR_COMPONENT/models/EXAMPLE.php
Look for the getListQuery() method and then look for this
if (!JFactory::getUser()->authorise('core.edit.state', 'com_example')){
$query->where('a.state = 1');
}
And change to this
if (!JFactory::getUser()->authorise('core.edit.state', 'com_example')){
$query->where('a.state = 1 AND '.$db->quoteName('created_by').' = '.JFactory::getUser()->get('id'));
}
Son Düzenleme: 9 yıl 7 ay önce Düzenleyen:Eduardo Mena
Lütfen sohbete katılmak için Giriş ya da Hesap açın.
Sayfa oluşturma süresi: 0.050 saniye