Skip to content

Commit f50b85a

Browse files
author
Andy McCormick
committed
more updates
1 parent 91cedc3 commit f50b85a

File tree

6 files changed

+122
-65
lines changed

6 files changed

+122
-65
lines changed

docs/_images/prolet_example.png

235 KB
Loading

docs/development/actions.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
[TOC]
1313

1414
## 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.
1616

17-
## How To Build An Amazing Add-on?
17+
## How To Build An Amazing Action?
1818
To generate an action we use the CLI to add the action to our existing add-on named "Amazing Add-on".
1919

2020
```
@@ -79,18 +79,18 @@ Actions are not available for use until they have been added to the `exp_actions
7979

8080
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.
8181

82-
### Run Migration
82+
### Run Migration To Activate
8383
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`.
8484

8585

86-
### Setting Flag
86+
### Setting Flag To Activate On Creation
8787
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`.
8888

8989

9090

9191
## AddonName/Module/Actions
9292

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.
9494

9595
```
9696
php system/ee/eecli.php make:action
@@ -108,7 +108,7 @@ amazing_add_on
108108
```
109109

110110

111-
### class [MethodName]
111+
### class [ActionName]
112112

113113
Inside `Module/Actions/ExampleAction.php` we see the following code generated for us:
114114

@@ -127,7 +127,7 @@ class ExampleAction extends AbstractRoute
127127
}
128128
```
129129

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.
131131

132132
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.
133133

@@ -179,7 +179,7 @@ Let's do something with our action to demonstrate how this would work.
179179
### Form Data
180180
In this example we want to insert a row into our database when a user submits a form.
181181

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`.
183183

184184

185185
Create our action:
@@ -189,9 +189,11 @@ What is the action name? ExampleAction
189189
What add-on is the action being added to? [amazing_add_on,...]: amazing_add_on
190190
```
191191

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.
193193

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.
195+
196+
Our action's code (`Module/Actions/ExampleAction.php`):
195197

196198
```
197199
<?php
@@ -221,7 +223,7 @@ class ExampleAction extends AbstractRoute
221223
}
222224
```
223225

224-
In our template:
226+
Our template code:
225227

226228
```
227229
<form method="post" action="/?ACT=41">
@@ -237,9 +239,9 @@ In our template:
237239
```
238240

239241

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.
241243

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:
243245

244246
```
245247
$aid = ee()->cp->fetch_action_id(`Amazing_add_on`, `ExampleAction`);
@@ -248,7 +250,7 @@ $aid = ee()->cp->fetch_action_id(`Amazing_add_on`, `ExampleAction`);
248250

249251
### Return Data
250252

251-
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.
252254

253255
Create our action:
254256
```
@@ -317,6 +319,13 @@ The response:
317319
```
318320
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`.
319321

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:
321323

324+
The response after disabling CSRF protection:
325+
326+
```
327+
...
328+
The Entry You Requested
329+
...
330+
```
322331

docs/development/custom-template-tags.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ lang: php
1717

1818
## Overview
1919

20-
An add-on's template tags can be used anywhere in templates to help edit content.
20+
TIP:If you are unfamiliar with Template Tags be sure to read the docs on [ExpressionEngine's template language](/templates/language.md) first.
21+
22+
Creating your own custom template tags allows you to display dynamic data from your add-on anywhere you want, in any template.
2123

2224
## Creating Template Tags
2325
Tags are created via the CLI by using the `make:template-tag` command.
@@ -28,10 +30,6 @@ php system/ee/eecli.php make:template-tag
2830

2931
Follow the prompts to add a tag file to your add-on.
3032

31-
Now, let's update the class to read the timezone that is passed in:
32-
33-
34-
3533
This will create an `Models/Tags` folder in your add-on.
3634

3735
```
@@ -62,11 +60,12 @@ class ExampleTag extends AbstractRoute
6260
}
6361
```
6462

65-
As we can see, the CLI has correctly created a new class using our tag's name in PascalCase as the class name.
6663

6764
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.
6865

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.
7069

7170

7271
## Tag Construction
@@ -96,7 +95,7 @@ Single tags are designed to return a single value. Tag pairs look like this:
9695

9796
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.
9897

99-
## Creating Single Tags
98+
## Creating Single Template Tags
10099
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.
101100

102101
```
@@ -138,7 +137,7 @@ This would render in the browser as:
138137
Here is some amazing text: ExpressionEngine is the best CMS in the world!
139138
```
140139

141-
## Creating Tag Pairs
140+
## Creating Tag Pair Template Tags
142141

143142
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:
144143

@@ -292,6 +291,8 @@ This typically looks something like this:
292291

293292
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.
294293

294+
295+
## Create A Tag With Variables
295296
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.
296297

297298
First, generate the tag (we're calling our tag "date and time" and adding it to our Amazing Add-On):

docs/development/fieldtypes/fieldtypes.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,24 @@ lang: php
1515

1616
[TOC]
1717

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.
1831

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.
2032

2133
## Basic File Structure
2234

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`.
2436

2537
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2638

0 commit comments

Comments
 (0)