You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development/actions.md
+24-15Lines changed: 24 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@
12
12
[TOC]
13
13
14
14
## Overview
15
-
Actions in ExpressionEngine are URL endpoints which are typically reached with the `ACT` query parameter. An example of this might be `http://myamazingsite.com/?ACT=43` where 43 is the ID given to an action registered in the `exp_actions` database table. These actions are tied to methods in an add-on which can be used to accept input from forms or run some sort of other functionality defined in the add-on.
15
+
Actions in ExpressionEngine are URL endpoints that are reached with the `ACT` query parameter. An example of this might be `http://myamazingsite.com/?ACT=43` where 43 is the ID given to an action registered in the `exp_actions` database table. These actions are tied to methods in an add-on which can be used to accept input from forms or run some sort of other functionality defined in the add-on.
16
16
17
-
## How To Build An Amazing Add-on?
17
+
## How To Build An Amazing Action?
18
18
To generate an action we use the CLI to add the action to our existing add-on named "Amazing Add-on".
19
19
20
20
```
@@ -79,18 +79,18 @@ Actions are not available for use until they have been added to the `exp_actions
79
79
80
80
If you want your action to be accessible immediately, you can either run the migration that was created by the CLI or set a flag in the CLI when creating the add-on.
81
81
82
-
### Run Migration
82
+
### Run Migration To Activate
83
83
After creating your action using the CLI run `$ php system/ee/eecli.php migrate`. When asked for the location, type in the name of your add-on. This will run all migrations that have not been ran for your add-on including entering the action into `exp_actions`.
84
84
85
85
86
-
### Setting Flag
86
+
### Setting Flag To Activate On Creation
87
87
On creation of an action, you can also specify to add it to the database after the CLI creates it. You can do this with the `--install` or `-i` flag by running your `make:action` command like so: `$ php system/ee/eecli.php make:action --install`.
88
88
89
89
90
90
91
91
## AddonName/Module/Actions
92
92
93
-
Once we've added an action to our add-on, an `Actions` folder is created inside our add-on's `Module` folder. The CLI will generate a class and respective file for us based on the method name we passed to the CLI when creating our action. In this case we added an action with a method named "ExampleAction" to Amazing Add-on.
93
+
Once we've added an action to our add-on, an `Actions` folder is created inside our add-on's `Module` folder. The CLI will generate a class and respective file for us based on the action name we passed to the CLI when creating our action. In this case we added an action named "ExampleAction" to Amazing Add-on.
94
94
95
95
```
96
96
php system/ee/eecli.php make:action
@@ -108,7 +108,7 @@ amazing_add_on
108
108
```
109
109
110
110
111
-
### class [MethodName]
111
+
### class [ActionName]
112
112
113
113
Inside `Module/Actions/ExampleAction.php` we see the following code generated for us:
114
114
@@ -127,7 +127,7 @@ class ExampleAction extends AbstractRoute
127
127
}
128
128
```
129
129
130
-
As we can see, the CLI has correctly created a new class using our method's name in PascalCase as the class name.
130
+
As we can see, the CLI has correctly created a new class using our action's name in PascalCase as the class name.
131
131
132
132
Inside of our class is the `process()` method. Anything we want to happen when a user reaches our action should be placed inside this `process()` function.
133
133
@@ -179,7 +179,7 @@ Let's do something with our action to demonstrate how this would work.
179
179
### Form Data
180
180
In this example we want to insert a row into our database when a user submits a form.
181
181
182
-
For this example we'll use a really basic form that would be found in our template which uses our action's endpoint as the action for the form. We know our action's ID from the `exp_actions` table and we're just going to collect the user's first name and last name. We'll then take that information and store it in our database. For the purpose of this example, we'll insert this into a custom table we've added to ExpressionEngien which just has columns `ID`, `first_name`, `last_name`.
182
+
For this example we'll use a really basic form that would be found in our template which uses our action's endpoint as the action for the form. We know our action's ID from the `exp_actions` table and we're just going to collect the user's first name and last name. We'll then take that information and store it in our database. For the purpose of this example, we'll insert this into a custom table we've added to ExpressionEngine which just has columns `ID`, `first_name`, `last_name`.
183
183
184
184
185
185
Create our action:
@@ -189,9 +189,11 @@ What is the action name? ExampleAction
189
189
What add-on is the action being added to? [amazing_add_on,...]: amazing_add_on
190
190
```
191
191
192
-
This creates our required files. Now we had some functionality to our action which will add the first and last name submitted from a form to our custom database table.
192
+
This creates our required files.
193
193
194
-
Our action code:
194
+
Now we had some functionality to our action which will add the first and last name submitted from a form to our custom database table.
@@ -221,7 +223,7 @@ class ExampleAction extends AbstractRoute
221
223
}
222
224
```
223
225
224
-
In our template:
226
+
Our template code:
225
227
226
228
```
227
229
<form method="post" action="/?ACT=41">
@@ -237,9 +239,9 @@ In our template:
237
239
```
238
240
239
241
240
-
**A note about action IDs.** For the example above, we looked up the action ID in the database. However, the action ID of your method may be different in your database than someone else as the IDs are auto-incremented by the database on insertion. Therefore, it's always best practice to fetch your action ID for use in a template by using the [`fetch_action_id()`](/development/legacy/libraries/cp.md#fetch_action_idclass-method) method from the `CP Class` library.
242
+
**A note about action IDs.** For the example above, we looked up the action ID in the database. However, the action ID of your method may be different in your database than someone else as the IDs are auto-incremented by the database on insertion. Therefore, when dynamically creating the form with a custom template tag, it's always best practice to fetch your action ID for use in a template by using the [`fetch_action_id()`](/development/legacy/libraries/cp.md#fetch_action_idclass-method) method from the `CP Class` library.
241
243
242
-
We would do this in our add-on with something like this:
244
+
We would do this in our add-on's template tag with something like this:
In this next example we are just creating an endpoint which will be reachable from servers outside of our domain. We are going to expect the application to use cURL or similar libray to post an ID to our endpoint. Upon receiving the request our action will return the name of the entry matching the ID if it exists.
253
+
In this next example we are just creating an endpoint which will be reachable from servers outside of our domain. We are going to expect the application to use cURL or similar library to post an ID to our endpoint. Upon receiving the request our action will return the name of the entry matching the ID if it exists.
252
254
253
255
Create our action:
254
256
```
@@ -317,6 +319,13 @@ The response:
317
319
```
318
320
This is because of the [`csrf_exempt` value](#cross-site-request-forgerycsrf-exemption) mentioned above. To fix this we can go into the `exp_actions` table of our database and update the `csrf_exempt` column to `1`.
319
321
320
-
Now when I send that same request, I simply get the entry title I requested.
322
+
Now when I send that same request, I simply get the entry title I requested:
Follow the prompts to add a tag file to your add-on.
30
32
31
-
Now, let's update the class to read the timezone that is passed in:
32
-
33
-
34
-
35
33
This will create an `Models/Tags` folder in your add-on.
36
34
37
35
```
@@ -62,11 +60,12 @@ class ExampleTag extends AbstractRoute
62
60
}
63
61
```
64
62
65
-
As we can see, the CLI has correctly created a new class using our tag's name in PascalCase as the class name.
66
63
67
64
Inside of our class is the `process()` method. Anything we want to happen when our template tag is used should be placed inside this `process()` function.
68
65
69
-
After your tag is created, you can use your tag by just using `{exp:[addon_name][tag_name]}`. In the example above, we created a tag named "Example Tag". We can now use the tag `{exp:amazing_add_on:example_tag}` and the text "My Tag" will be outputted to my template.
66
+
After your tag is created, you can use your tag by just using `{exp:[addon_name][tag_name]}`.
67
+
68
+
In the example above, we created a tag named "Example Tag". We can now use the tag `{exp:amazing_add_on:example_tag}` and the text "My Tag" will be outputted to my template.
70
69
71
70
72
71
## Tag Construction
@@ -96,7 +95,7 @@ Single tags are designed to return a single value. Tag pairs look like this:
96
95
97
96
Tag pairs allow you to process the information contained between the tags. In the above example, the text between the pairs would be encoded with XML entities.
98
97
99
-
## Creating Single Tags
98
+
## Creating Single Template Tags
100
99
Single Tags are the easiest template tags to create and process. Here we'll add a single tag to our add-on using the CLI. We'll name the tag Amazing Text.
101
100
102
101
```
@@ -138,7 +137,7 @@ This would render in the browser as:
138
137
Here is some amazing text: ExpressionEngine is the best CMS in the world!
139
138
```
140
139
141
-
## Creating Tag Pairs
140
+
## Creating Tag Pair Template Tags
142
141
143
142
Often you will want to process content contained between a pair of tags. Let's create a simple tag that makes text bold to illustrate how this is done. Our example plugin will have this syntax:
144
143
@@ -292,6 +291,8 @@ This typically looks something like this:
292
291
293
292
In the snippet above, we're passing in the `channel` and `limit` as parameters. We're then expecting the Channel Entries tag to replace the `{title}` and `{body}`**variables** when the tag is parsed. Now, let's do something similar to our add-on.
294
293
294
+
295
+
## Create A Tag With Variables
295
296
Let's add a tag to our add-on that will render the current date and time. The user can pass in their timezone and the tag will return the current Date and time.
296
297
297
298
First, generate the tag (we're calling our tag "date and time" and adding it to our Amazing Add-On):
Copy file name to clipboardExpand all lines: docs/development/fieldtypes/fieldtypes.md
+14-2Lines changed: 14 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,12 +15,24 @@ lang: php
15
15
16
16
[TOC]
17
17
18
+
TIP: For an overview of what a Fieldtype is, read the [Fieldtype Overview docs](/fieldtypes/overview.md).
19
+
20
+
21
+
## Generating A Custom Fieldtype
22
+
23
+
Adding a custom fieldtype to your add-on is easy with the `make:fieldtype` command.
24
+
25
+
```
26
+
$ php system/ee/eecli.php make:fieldtype
27
+
compatiblity
28
+
```
29
+
30
+
Follow the prompts to complete the setup of your custom fieldtype.
18
31
19
-
NOTE: Fieldtypes can also be **generated quickly by the Command Line Interface (CLI)**. Refer to the [make:addon command](cli/built-in-commands/make-addon.md) for more information.
20
32
21
33
## Basic File Structure
22
34
23
-
All fieldtypes should be placed into the `system/user/addons` folder in a package and be named after that package name. So in a packaged named google_maps the fieldtype file will be `ft.google_maps.php`. All fieldtypes must inherit from the `EE_Fieldtype` base class and they must provide an \$info array with a name and version number.
35
+
Once generated via the CLI a file named `ft.[addon_name].php` will created in your add-on's folder. All fieldtypes must inherit from the `EE_Fieldtype`.
24
36
25
37
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
0 commit comments