Part 1: setting up the project

By the end of this part, you will have:

  • a 4D project MyBlog with the BSPK Tools component;
  • BWEB installed, with a first domain myblog.test;
  • access to the BWEB administration with the DEV account;
  • a POST table for the articles, its dataclass class, and a few test articles.

1. Create the 4D project

  1. Launch 4D 21.
  2. Create a new project and name it MyBlog.
  3. Keep it open locally: the BWEB installation refuses a compiled project or one opened from a remote server.

You can also follow this tutorial in an existing project. In that case, read the section "Installing BWEB in a database that already serves web pages" of Installing BWEB: among other things, the installation changes the On Web Connection database method and the web settings.

2. Declare the component

BWEB ships in the BSPK Tools component, published on GitHub in the bspoke-dev/BSPK-Tools repository. The recommended way is to declare it as a project dependency:

  1. Menu Design > Project Dependencies.
  2. + button, GitHub tab, repository path bspoke-dev/BSPK-Tools.
  3. Pick a specific version (a tag), confirm, then restart 4D.

On restart, 4D downloads the component, which brings the 4D components it needs by itself. Copying the component into the project's Components folder also works, but do not do both. Details are in Installing BWEB.

3. Install BWEB

  1. Run the _BSPK_LAUNCH method: the component's launcher opens.
  2. Click BWEB. The Before installing screen lists what the installation will change in your database. Read it, then click I have read these changes and I accept them.
  3. Accept the licence, then click Start installation. The wizard ticks its steps as it goes.
  4. At the SSL certificate step, give your cert.pem and key.pem files, or continue without a certificate for a local trial.
  5. 4D restarts during the structure step: this is expected, the installation resumes by itself.
  6. When the wizard asks for the name of your first domain, enter myblog.test. It is a host name: no https://, no port, no slash.
  7. Accept adding this name to the machine's hosts file, so that myblog.test answers locally. This change requires administrator rights; if it fails, a message gives you the line to add yourself.

Your structure now contains many BSPK_* tables: they belong to BWEB. Do not delete or rename them.

4. Log in to the administration

  1. In the launcher, click Test BWEB: the browser opens https://myblog.test/bweb.
  2. Without a certificate, or with a self-signed one, the browser shows a security warning: you can proceed for a local trial.
  3. The installation created an account whose login is DEV, with no password. The first time you log in as DEV, BWEB asks you to choose the password and confirm it.
  4. You land on the BWEB administration.

The DEV account belongs to the system group: it holds every right, including the right to edit pages with the dev panel.

A fresh installation starts in DEV mode (DEV_PARAMETERS parameter file). That is what you want while developing; on a production server, delete DEV_PARAMETERS and PREPROD_PARAMETERS. See The parameter files.

5. Create the POST table

Back in 4D, open the structure editor and create a POST table with the following fields:

FieldTypeIndexRole
uuidKeyAlpha, UUID format, auto-generatedYes (primary key)Article identifier
titleAlpha (255)YesTitle
slugAlpha (255)YesReadable address of the article, computed from the title
summaryTextNoSummary shown in lists
contentTextNoFull content, as HTML
isPublishedBooleanYesDraft (false) or published (true)
publicationDateDateYesPublication date
  • uuidKey as primary key: this is the convention of BWEB tables, and this key will identify the article in the address of the editing page.
  • slug gives the public blog readable addresses: /article/my-first-article rather than an identifier.
  • isPublished lets you write drafts: only published articles will appear on the public blog. Give it the property that rejects NULL values (never_null in the catalog): a NULL boolean is neither true nor false for an If.

Save the structure.

6. Create the POST dataclass class

The functions your buttons will call live in the table's dataclass class: the file Project/Sources/Classes/POST.4dm. Create it; for now it only holds its declaration:

Class extends DataClass

The Class extends DataClass line matters: in an event's class list, the dev panel only offers classes that extend DataClass, Entity, EntitySelection or WebFormController.

Optional: classes generated by BWEB. The BSPK_UTIL_UPDATE_DATACLASS method can create the POST, POSTEntity and POSTSelection classes for you and inject BWEB's base code into them (change history included). For your application's tables, it only does so when the vb_AddBSPKDataClass parameter is true in the vo_Param of your parameter files. The injected code sits between the /*** START BSPK ***/ and /*** END BSPK ***/ tags and is rewritten on every pass: write yours outside them. If the method creates classes, it restarts 4D. This tutorial does not need it.

7. Add a few test articles

To have data to show as early as part 2, run this code once, in a method or with the launcher's code execution button:

var $post : 4D.Entity
var $i : Integer
For ($i; 1; 3)
	$post:=ds.POST.new()
	$post.title:="Test article "+String($i)
	$post.slug:="test-article-"+String($i)
	$post.summary:="Summary of article "+String($i)
	$post.content:="<p>Content of article "+String($i)+".</p>"
	$post.isPublished:=($i#3)  // the third one stays a draft
	$post.publicationDate:=Current date-$i
	$post.save()
End for

To browse or fix this data from 4D, the launcher also opens the ATL, the component's table browsing tool.

8. Check

Before moving on, check that:

  • the login page of https://myblog.test/bweb shows up, and you can log in as DEV;
  • the POST table exists with its seven fields, and holds three articles;
  • the POST class exists and starts with Class extends DataClass.

Next: Part 2: the back-office.

See also