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

front end component view

pred 9 rokmi 6 mesiacmi #789 od Matthew
front end component view bolo vytvorené 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

Prosím Prihlásiť alebo Registrácia pre zdieľanie konverzácie.

pred 9 rokmi 6 mesiacmi - pred 9 rokmi 6 mesiacmi #794 od Randy Carey
Odpoveď od Randy Carey na tému 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.
Posledný krát upravené:pred 9 rokmi 6 mesiacmi Randy Carey
Nasledujúci užívateľ(ia) povedali ďakujem: Matthew

Prosím Prihlásiť alebo Registrácia pre zdieľanie konverzácie.

pred 9 rokmi 5 mesiacmi - pred 9 rokmi 5 mesiacmi #816 od Eduardo Mena
Odpoveď od Eduardo Mena na tému 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
Posledný krát upravené:pred 9 rokmi 5 mesiacmi Eduardo Mena

Prosím Prihlásiť alebo Registrácia pre zdieľanie konverzácie.

Čas vytvorenia stránky: 0.052 sekúnd
Funguje na Kunena fórum

We use cookies so that you can place orders and we can provide a better service. You can control the use of cookies at the individual browser level. If you reject cookies, you may still use our website, but your ability to use some features or areas of our website may be limited.