CB auto action include php file and substitutions

1 month 3 weeks ago - 1 month 3 weeks ago #327282 by activha
Hello

Instead of writing the code in the input box I use
include_once('/var/html/myfile.php')

But when trying to make substitutions like
echo '<h1>test echo</h1> : [var1_user_id] - [var1_params_event] -  [var1_asset] - [cb:parse function="asset" class="var5" /]';

I don't get the substitutions while if I insert the same code in the input box things works fine.

I use the output : return (empty) in the auto action

Can you tell me what I missed and where ?

Please Log in to join the conversation.

1 month 3 weeks ago #327285 by krileon
Substitutions are ran on the code before it's converted to code. So that is completely expected behavior. This allows the PHP to utilize the results of a substitution. You need to run your string through the ->string function of the $action variable provided by a Code action for it to parse for substitutions. This was explained below.

www.joomlapolis.com/forum/255-developer-members-support/244490-cb-activity-new-use-for-spots-display?start=18#327210


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 to join the conversation.

1 month 3 weeks ago #327286 by activha
You mean that I cannot use any substitutions in an external file included and that I must use $action, $user and $variables ?

Please Log in to join the conversation.

1 month 3 weeks ago #327288 by krileon
You need to call the substitution parsing function on anything you want to support substitutes when used in an external file. Your include is a part of the execution of PHP this means substitutions have already parsed and are done before your file is even included as again substitutions are applied to the code string before it's converted to usable PHP. So if you want to use substitutions in your included file you need to use the ->string function. Example as follows.

FROM:
echo '<h1>test echo</h1> : [var1_user_id] - [var1_params_event] -  [var1_asset] - [cb:parse function="asset" class="var5" /]';
TO:
echo $action->string( $user,  '<h1>test echo</h1> : [var1_user_id] - [var1_params_event] -  [var1_asset] - [cb:parse function="asset" class="var5" /]' );


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.
The following user(s) said Thank You: activha

Please Log in to join the conversation.

1 month 3 weeks ago #327302 by activha
For Auto actions and with CB Activities triggers, can I access the owner of the activity with a variable ? or shall I write something like this to access the owner user object:
$user_id = $action->string( $user,'[var1_user_id]');
$cbUser =&  CBuser::getInstance($user_id);
$alias = $cbUser->replaceUserVars ('[cb:userdata field="alias" /]');

I've seen var8 but it seems the self user not the owner

Please Log in to join the conversation.

1 month 3 weeks ago #327308 by krileon
$user variable is the action user. It's their user table object. It's not a CBuser instance. You'll need to create a CBuser object from their user id (e.g. $user->id). You can then use getField API to get a field value like shown below or you can just use ->string function with substitutions.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18361-obtaining-field-values-through-getfields-api

getField API
$cbUser	=	CBuser::getInstance( $user->getInt( 'id', 0 ), false );
$alias	=	$cbUser->getField( 'alias' );

->string function
$alias	=	$action->string( $user, '[alias]' );


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 to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.179 seconds

Facebook Twitter LinkedIn