× Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues

front end component view

9 Jahre 6 Monate her #789 von Matthew
front end component view wurde erstellt von Matthew
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

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

9 Jahre 6 Monate her - 9 Jahre 6 Monate her #794 von Randy Carey
Randy Carey antwortete auf front end component view
You can edit/override the component's template to accomplish this.  Use a line of code like this
$belongs_to_user = JFactory::getUser()->id == $item->created_by; 
to 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 is
if(! JFactory::getUser()->id == $item->created_by){
   continue;
}
and 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.
Letzte Änderung: 9 Jahre 6 Monate her von Randy Carey.
Folgende Benutzer bedankten sich: Matthew

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

9 Jahre 6 Monate her - 9 Jahre 6 Monate her #816 von Eduardo Mena
Eduardo Mena antwortete auf front end component view
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
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'));
}
Users that are not allowed to edit state will only see their own items
Letzte Änderung: 9 Jahre 6 Monate her von Eduardo Mena.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

Ladezeit der Seite: 0.053 Sekunden
Powered by Kunena Forum

Wir verwenden eigene Cookies und Cookies von Drittanbietern, um Ihr Nutzererlebnis zu verbessern und Ihnen einen optimalen Service zu bieten. Wenn Sie die Website weiter nutzen, gehen wir davon aus, dass Sie mit unserer Cookie-Politik einverstanden sind.