Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
examples:builder:multi_attachment [2020/09/18 20:06] pdsci |
examples:builder:multi_attachment [2021/12/09 10:56] (current) pdsci-admin [Multiple media/file attachment: attachMany] |
||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ====== Multiple media/file attachment: attachMany ====== | ====== Multiple media/file attachment: attachMany ====== | ||
| - | With the // | + | With the // |
| <WRAP tip> | <WRAP tip> | ||
| Line 18: | Line 18: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| + | ===== Preparation ===== | ||
| + | Prerequisites are\\ | ||
| + | * an installed [[https:// | ||
| + | * any source code editor or e.g. the [[https:// | ||
| + | * a database table for records to attach the media to | ||
| + | * a form (at least in backend) to display the media | ||
| + | * some media already uploaded to the media manager or ready to do so | ||
| + | |||
| + | Required skills\\ | ||
| + | * how to work with builder | ||
| + | * how to create a plugin with builder | ||
| + | * how to create tables and forms with builder | ||
| + | |||
| + | ===== Step 1: Extend the base model ===== | ||
| + | |||
| + | The base model requires to know the type of desired relation as well as the name of the relation. This name can be seen like a field name of a database-table.\\ | ||
| + | |||
| + | The base model is located in the plugin directory, subdirectory //models// using the singular of the related db-table name. In our example in the namspace //pds// the plugin //library// with a //book// model this is:\\ | ||
| + | / | ||
| + | |||
| + | Here, the // | ||
| + | |||
| + | {{: | ||
| + | <WRAP clear /> | ||
| + | \\ | ||
| + | These are the lines of code to add for the library example to add images of book covers with a new related field called // | ||
| + | <sxh php> | ||
| + | // add a relation for a SINGLE image, field name is ' | ||
| + | // this table must not have a field named ' | ||
| + | public $attachMany = [ | ||
| + | ' | ||
| + | ]; | ||
| + | </ | ||
| + | \\ | ||
| + | |||
| + | ===== Step 2: Prepare the form ===== | ||
| + | Next step is to complete the form with an additional field - the **File upload** widget to upload and display media and/or files:\\ | ||
| + | |||
| + | {{: | ||
| + | <WRAP clear /> | ||
| + | \\ | ||
| + | ===== Step 3: Upload media/files ===== | ||
| + | |||
| + | Finally, in the backend form view of the plugin, a file can be uploaded by clicking on the //file upload symbol// - the area below the 'Page Views' title in the example:\\ | ||
| + | |||
| + | {{: | ||
| + | <WRAP clear /> | ||
| + | \\ | ||
| + | Now the form is ready to attach multiple images and/or files to each record.\\ | ||
| + | ---- | ||
| + | \\ | ||
| + | Back to [[: | ||
| + | |||