Skip to Content Skip to Menu

[SOLVED] How to use the PHP code execution in the Auto Action?

  • carin
  • carin
  • OFFLINE
  • Posts: 417
  • Thanks: 18
  • Karma: 0
10 years 8 months ago - 10 years 8 months ago #241437 by carin
I could not find any docu on the matter.

I need to run a query on a jDownloads field. First I tried the Method "Query" with a static cat ID which worked, but I need to pull the cat IDs from my custom cb field. So I tried this code with Methode "PHP (create function)":
Code:
$db = JFactory::getDbo(); $query = $db->getQuery(true); $query->SELECT(cb_mycheckboxsubfield) ->FROM(#__comprofiler) ->WHERE(user_id=[user_id]); $db->setQuery($query); $catidString = str_replace ('|*|', ',',$db->loadResult()); $query = $db->getQuery(true); $query->UPDATE(#__jdownloads_cats) ->SET(cat_description='[lastname]') ->WHERE cat_id IN ($catidString);

That gives an error:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ')' in .../components/com_comprofiler/plugin/user/plug_cbautoactions/models/code.php(59) : runtime-created function on line 4 Fatal error: Function name must be a string in .../components/com_comprofiler/plugin/user/plug_cbautoactions/models/code.php on line 60


What do I need to do to make that work?

CB 2.0
Last edit: 10 years 8 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 8 months ago #241458 by krileon
Your PHP isn't valid. For example look at the bottom query when you use ->WHERE. I suggest reviewing all of your code carefully and ensure you've supplied valid markup.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • carin
  • carin
  • OFFLINE
  • Posts: 417
  • Thanks: 18
  • Karma: 0
10 years 8 months ago - 10 years 8 months ago #241462 by carin
Thanks, but that code works in other places. What exactly is wrong with WHERE cat_id IN ($catidString);? Even when I put in static values the same error message appears.

CB 2.0
Last edit: 10 years 8 months ago by carin.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 8 months ago - 10 years 8 months ago #241486 by krileon
I don't see how that could possibly work.

Code:
->WHERE cat_id IN ($catidString);

That is not valid PHP. It likely should be as follows.

Code:
->WHERE( '`cat_id` IN ( $catidString )' );

The same with several of the other usages missing quotes, escaping, etc..


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 10 years 8 months ago by krileon.
The following user(s) said Thank You: nant

Please Log in or Create an account to join the conversation.

  • carin
  • carin
  • OFFLINE
  • Posts: 417
  • Thanks: 18
  • Karma: 0
10 years 8 months ago #241510 by carin
Thanks for the hint, you are right. I corrected the query and it works now.

CB 2.0
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum