Add PHP code to a code plug-in project to modify a pattern
instance when the pattern instance is generated by a pattern user.
Before you begin
Before you can complete this task, you must have completed
the following tasks:
About this task
You can add PHP code to a code plug-in project by selecting
a PHP script, which runs when a pattern instance is generated. You
can choose whether to write the output of this script to a file. For
example, you can write a PHP script that creates an ESQL file that
is used in your user-defined pattern.If you added
PHP support when you created the code plug-in, a PHP template and
example scripts are created and added to the project. Alternatively,
you can write your own PHP script. Regardless of how the script is
created, you must add your own code within the script to complete
the steps you require when the pattern instance is generated. For
examples of PHP code for completing common tasks, see Examples of PHP API code. For reference information about the
PHP pattern authoring API, see PHP API for user-defined patterns.
Procedure
To select a PHP script to run when a pattern instance
is generated:
- If the Add Java or PHP Code window
is not open, in the Pattern
Configuration tab of
the Pattern Authoring editor, click Add.
The Add Java or PHP Code window opens.
- In the Type of code list, select
PHP.
- In the Project name list, select
the project or plug-in that contains the PHP script that you want
to run when a pattern instance is generated. If the required plug-in
is installed, but is not in your workspace, click Browse and
select the required plug-in.
- In the PHP file name list, select
the name of the script you want to run when a pattern instance is
generated.
The PHP file name list
shows all the PHP scripts in the project or plug-in that you selected.
- Optional: To write the output of the PHP script
to a file, select Write the output from the PHP file into
an output file.
- In the Pattern instance project list,
select the pattern instance project in which you want to include the
output file.
- In the Output file name field,
enter a name for the output file.
You can include a path
in this field, for example scripts/example.mqsc to
write the output to the scripts folder.
- Click OK.
The Add
Java or PHP Code window closes and the PHP script that
you selected is shown in the Java and PHP Code section
of the Pattern
Configuration tab.
- Optional: The Java and
PHP code listed in the Java and
PHP Code section of the Pattern
Configuration tab runs
from top to bottom when a pattern instance is generated. To change
the order in which the code runs, select the entry you want to move
in the Java and PHP Code section
and click the Up or Down button
to change the position of the entry in the list.
What to do next
In the PHP script that you selected to run when the pattern
instance is generated, you must now write the code to perform the
steps you require. For examples of PHP code for completing common
tasks, see Modifying pattern instances by using PHP. For reference information
about the PHP pattern authoring API, see PHP API for user-defined patterns.