PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Core/Contents/Doc/en/developer-global-content.md

http://github.com/infinitas/infinitas
Markdown | 116 lines | 75 code | 41 blank | 0 comment | 0 complexity | d57a0e796b6d46ee2e22815e6b229e36 MD5 | raw file
  1. The `GlobalContent` model provides a base for building models with _content_ such as blogs, cms, producs and more. It makes it easy to do a number of things such as search, tag and SEO. The main advantages is that it has all the usual details such as `title`, `description`, `created`, `image`, `group_id`, `author_id` and elements that make building forms much easier.
  2. Some examples of the `GlobalContent` model in action include the Blog and Cms plugins. Both of these make use of the model as they share a large amount of functionality such as `title`, `body`, `author` and more.
  3. ### Background
  4. The Contents plugin has a behavior that is able to attach it self to models where this functionality is required. Once attached it will automatically create all the required relations and alter finds to include other details such as the `author` or `group` the content belongs to.
  5. Besides setting a flag in a model and the optional use of the elemnts to make building forms easier, there are no other changes required. This makes it realy easy to build content related models.
  6. As the `GlobalContent` model creates links to many different things it becomes easy to do a number of things, for example finding any content by a specific user or all the content that is for a specific group of users regardless of what type of content it is for.
  7. ### Examples of use
  8. #### Blog
  9. ##### Contents plugin
  10. - title
  11. - slug (for SEO urls)
  12. - body
  13. - author\_id / alias
  14. - editor\_id / alias
  15. - group\_id (create posts for specific groups)
  16. - image (main post image)
  17. - category
  18. - tags
  19. ##### Blog customisation
  20. - Order content by date
  21. - active (enable / disable posts)
  22. - views (track view count)
  23. - rating
  24. - parent\_id (multi page posts)
  25. - ordering (used for multi page posts)
  26. > The main thing added here to make `blog` like content is how data is ordered. There is also the optional `multi page posts` which is done by adding the `parent\_id` field.
  27. #### Cms
  28. ##### Contents plugin
  29. - title
  30. - slug (for SEO urls)
  31. - body
  32. - author\_id / alias
  33. - editor\_id / alias
  34. - group\_id (create posts for specific groups)
  35. - image (main post image)
  36. - category
  37. - tags
  38. ##### Cms customisation
  39. - start / end date
  40. - active
  41. - rating
  42. > The main customisation for cms content is being able to configure pages to become active or disabled after a certain date.
  43. Status and ratings are also going to be moved into the Contents plugin so that there is even less required to build other content models. Most fields are optional but do make development of content related stuff much easier.
  44. ### Usage
  45. To get started using the `GlobalContent` model you will need to set a flag in your model so that when the Events are triggered the behavior is automatically attached which adds the required relations and functionality to your model.
  46. public $contentable = true;
  47. You can also include the behavior using the normal `$actsAs` provided by CakePHP to attach this functionality.
  48. Once the `GlobalContent` has been configured you would need to adjust your forms to include the new fields. This can be done using the `FormHelper` for more fine grained control of the form. Alternativly you can use the provided elements that provides easy access to most of the functionality.
  49. #### Content
  50. The content element provides the fields for general data such as `title` and `description`. You can disable some fields that are not required such as the `image` or `intro`.
  51. For all the available fields you can use
  52. echo $this->element('Contents.content\_form');
  53. Or exclude some from the form:
  54. echo $this->element('Contents.content\_form', array(
  55. 'image' => false,
  56. 'intro' => false
  57. ));
  58. The model that the `GlobalContent` relates to is normally taken from the default model that is currently loaded. For example if done in the Blog plugin through the `BlogPostsController` the model would be `Blog.BlogPost` as that is what the controller would load by default. If you wanted to specify something else you would pass it to the element:
  59. echo $this->element('Contents.content\_form', array(
  60. 'model' => 'Example.Example'
  61. ));
  62. #### Meta
  63. The `meta_form` element provides the fields to save basic metat data about the post. This includes things such as the `meta description`, `meta keywords` and `canonical` url which are all for SEO purposes.
  64. echo $this->element('Contents.meta\_form');
  65. #### Author
  66. The `author\_form` will help with storing who the creator and editor of the content was. This can be used for doing lookups by author or accountability.
  67. echo $this->element('Contents.author\_form');
  68. ### Form example
  69. You have a blog post model and want to make use of this functionality. Your form might look something like the following.
  70. echo $this->Form->create('BlogPost');
  71. echo $this->Form->input('id'); // BlogPost.id field
  72. echo $this->element('Contents.content\_form'); // all the content fields
  73. echo $this->Form->input('active'); // BlogPost.active field
  74. echo $this->Form->end();
  75. Making use of the built in Infinitas `admin\_add()` and `admin\_edit()` controller methods, the content would all be saved correctly. If you are overriding thouse methods be sure to call `saveAll()` so that all the data can be saved.