Building Your Application

Static Pages

Static pages display fixed content that doesn't change dynamically. While they might not be truly static in the sense that you can still incorporate variables, they primarily serve to present unchanging information.

A common example of a static page is the "Terms and Conditions" section. Here's a look at a typical static page template (app/views/themes/fuwafuwa/terms.html):

<f3:inject id="content">
<div class="mx-auto my-6 format lg:format-lg dark:format-invert">
<h2><strong>Terms and Conditions</strong></h2>

<p>Welcome to {{@APP.title}}!</p>

<p>These terms and conditions outline the rules and regulations for the use of {{@APP.title}}'s Website, located at
    <code>{{@HOST}}</code>.
</p>
...

As you can see, this template includes dynamic elements like {{@APP.title}} and {{@HOST}}, allowing for some level of customization.

Fuwafuwa Framework's templating system automatically wraps static pages within a default layout (typically found in /themes/fuwafuwa/templates/template.html). This provides a consistent look and feel across your application. If you need to modify the default layout, create a copy in the app/views/user/templates directory and make your changes there.

Dynamic Pages

Dynamic pages display content that changes based on user interactions or other factors. To create a dynamic page, you'll typically work with three components: models, views, and controllers.

Let's say you want to display user information based on a provided login parameter (e.g., /user/view?login=admin). Here's a breakdown of the required files and code:

Model (app/controllers/user/model/user.php)

<?php
namespace Model;

class User extends \Fuwafuwa\BaseModel {
    function __construct(\Fuwafuwa\Db $db) {
        parent::__construct($db, 'user', ['keys' => 'login',]);
    }
}

Controller (app/controllers/user/user.php)

<?php
// app/controllers/user/user.php
class User {
    function execute($f3, $action) {
        if (method_exists($this, $action)) {
            $this->$action($f3);
        } else {
            $f3->error(404);
        }
    }

    function view($f3) {
        $user = m('\Fuwafuwa\Model\User');
        $user->retrieve($f3['GET.login']);
        $f3['user'] = $user->cast();
        $f3['content'] = 'view-user';
    }
}

View (app/views/user/view-user.html)

<!-- app/views/user/view-user.html -->
<f3:inject id="content">
    <table>
        <tr>
            <td>Login</td>
            <td>{{ @user.login }}</td>
        </tr>
        <tr>
            <td>Fullname</td>
            <td>{{ @user.fullname }}</td>
        </tr>
        <tr>
            <td>Token</td>
            <td>{{ @user.token }}</td>
        </tr>
    </table>
</f3:inject>

By following this structure, you can create dynamic pages that display data based on user input or other criteria.

Key Points:

Static pages are primarily for content that doesn't change frequently. Dynamic pages involve models, views, and controllers to handle data and user interactions. Fuwafuwa's templating system simplifies the creation of both static and dynamic pages.