-
- What is DG3
- The different components
- Requirements for running DG3
- Installation of DG3
- Additional installation steps
- Select which web server to use
- Hello World application
- Intro to CMS
- Setting up DG3 as a CMS
- Editing pages
- More about pages and urls
- Structuring a page using the grid
- Adding menu to pages
- Add images to the application
- More formating
- Sending email from contact us
- Adding menu to template
- Deploy the web site
- Storing the pages in database
- Create record
- Auto fill field
- Field validation
- Enable save button validator
- Add new button to template
- View document
- List documents
- Fix selection in menus in template
- CRUD Create Read Update Delete
- Intro to blogs
- Add user authentication
- Bootstrap authentication
- Let user change their passords
- Add reset password
- Login dialog box
- Extending the CMS to a blog
- Extend table for blogging
- Edit blog entry
- View blog entry
- User registration
- User password validation
- User field validation
- User auto login
- User extra registration fields
Extend table for blogging
For the blog, we have extended the table with a few extra fields. The type and author field has to be added to the editarticle we have in the cms as well as the new editblogentry. Since the fastest way to create new similar editdocument that just have a few extra fields is to create a new from an existing page, we do these changes to the editarticle first and then create a new editblogentry form this new version.
Extend the editarticle with new fields
To populate the new fields in editarticle with the values needed, we have to add them as hidden fields. We could set these fields as values in the table, but then we can not override with default values in DG3 as DG3 only assign default values to empty fields. Setting default values using formulas in the table should therefor just be used during upgrade of the tables or not at all, since you can do this by using DQLs instead. The DQL route is better when you already have deployed the solution to a server as you either will need to update twice, one with formulas and one without. With a simple DQL, you can do it whenever you want. A DQL that update your new fields with default values can look like this.
for Articles with type = blank; modify records author := "high"; type := article.
This little DQL simply walks through all record that do not have a value for type and sets it. Notice quotes on the author and no quotes on the article statement in the field assignments. This comes from that author is a text field and type is a choice field. The selection of fields without a value is done by the with type = blank; in the for. This is our first DQL and will soon find that this manipulation language can solve almost all kinds of problems much simpler and faster than SQL. You can check that you DQL do the updates of the table by right click on the table and open in table view or record view.
<h3>[% if xdg3.url.recordno == -1 %]Create a new blog article[% else %]Edit article[% endif %]</h3> [! field id !][! field type !][! field author !]
The new fields in editarticle. Both will be set to hidden and the type will get a default value set to article. This time you have to use quotes as DG3 send all data as strings to the server. This have to do with the way the default filter works. So what you really do is set a default value as a string and not as a formula that is then set to the field value if no other value is present. We have also added a better heading that checks to see if we are creating a new article or editing one. The technique is to use a if tag (we use the escaped form [% and %] for tags in pages) and check the value xdg3.url.recordno, as this will have a value of -1 on new record and a value of 0 or higher on edit a record. This is the record position in our returned query when searching in the table. We will come back to how this works soon.
The default value is set and remember quotes if you are hard coding values. If you want to use a livetext value for the default value, you can write that to the default value without quotes. Ex. to pick a value form the url, you can simply write xdg3.url.queryfieldtouse in the default value. If you want a username like in this solutuin, simply add user.username. To get a username, the user have to be logged in to the system.