Manifest File

local/Acme/HelloWorld/manifest.yml
modules:
    Acme_HelloWorld:
        # Module version is used in migration scripts
        version: 0.1.0
        # Bootstrap only after required modules
        require: { module: { FCom_Core: 0.1.0 } }
        # Short description for module listing and marketplace
        description: "Hello World Fulleron Module"

        # Specify instructions for specific areas
        areas:
            FCom_Frontend:
                # Automatically use views and layout files in the module
                auto_use: [ views, layout ]
                # Declare routes
                routing:
                    # /hello URL will dispatch this action
                    - [ /hello, Acme_HelloWorld_Frontend_Controller.index ]

Module Run Level

In admin, go to System > Installed Modules, find Acme_HelloWorld module, set run level as REQUIRED

Quick Page

local/Acme/HelloWorld/Frontend/views/static/hello/world.html.twig
<!--{ title: Hello, World! }-->
<!--{ meta_description: Testing hello world static page }-->
<!--{ meta_keywords: fulleron, hello, world }-->

<h1>{{ 'Hello, World!' |_ }}</h1>

Go to http://yourdomain.com/fulleron/hello/world

Controller

local/Acme/HelloWorld/Frontend/Controller.php
<?php

class Acme_HelloWorld_Frontend_Controller extends FCom_Frontend_Controller_Abstract
{
    public function action_index()
    {
        $this->layout('/hello');

        $hellos = $this->Acme_HelloWorld_Model_Hello->orm()->order_by_desc('created_at')->find_many();

        $this->view('acme/hello')->set('hellos', $hellos);
    }

    public function action_index__POST()
    {
        try {
            $data = $this->BRequest->post('hello');

            $data = $this->BUtil->arrayMask($data, 'author,email,message');

            $this->Acme_HelloWorld_Model_Hello->create($data)->save();

            $this->view('email/hello')->set($data)->email();

            $this->message('Thank you for your feedback');
        } catch (Exception $e) {
            $this->message($e->getMessage(), 'error');
        }
        BResponse::i()->redirect('hello');
    }
}

Layout & Views

local/Acme/HelloWorld/Frontend/layout.yml
/hello:
    - { include: base }
    - { hook: main, views: acme/hello }
local/Acme/HelloWorld/Frontend/views/acme/hello.html.twig
<h1>{{ 'Say Hello, World!' |_ }}</h1>

<form class="form-horizontal" action="{{ APP.href('hello') }}" method="post">
    <fieldset>
        <div class="form-group">
            <label for="author" class="form-label">{{ 'Your Name:' |_ }}</label>
            <input id="author" name="hello[author]" placeholder="Clark Kent" required>
        </div>
        <div class="form-group">
            <label for="email" class="form-label">{{ 'Your Email:' |_ }}</label>
            <input id="email" name="hello[email]" placeholder="clark@example.com" required>
        </div>
        <div class="form-group">
            <label for="message" class="form-label">{{ 'Your Message:' |_ }}</label>
            <textarea id="message" name="hello[message]" required></textarea>
        </div>
        <button type="submit" class="btn btn-primary">{{ 'Say Hello!' |_ }}</button>
    </fieldset>
</form>

<dl>
{% for hello in THIS.get('hellos') %}
    <dt>From {{ hello.get('author') }} at <em>{{ hello.get('created_at') |date('F jS g:ia') }}</em></dt>
    <dd>{{ hello.get('message') }}</dd>
{% endfor %}
</dl>

local/Acme/HelloWorld/Frontend/views/email/hello.html.twig
{% set data = THIS.get('data') %}

<!--{ subject: Thank you for your feedback, {{ data.author }} }-->
<!--{ from: Hello World Module <hello@example.com> }} }-->
<!--{ to: {{ data.author }} <{{ data.email }}> }} }-->

Hello, {{ data.author }}!

Your feedback has been accepted:

{{ data.message }}

--======--

<html>
<body>
    <h2>Hello, {{ data.author }}</h2>

    <p>Your feedback has been accepted:</p>

    <pre>{{ data.message }}</pre>

</body>
</html>


Models

local/Acme/HelloWorld/Model/Hello.php
<?php

class Acme_HelloWorld_Model_Hello extends FCom_Core_Model_Abstract
{
    static protected $_table = 'acme_hello';   # declare class table name
    static protected $_origClass = __CLASS__;  # save original class name for potential overrides

}
local/Acme/HelloWorld/Migrate.php
<?php

class Acme_HelloWorld_Migrate extends BClass
{
    public function install__0_1_0()
    {
        $tHello = $this->Acme_HelloWorld_Model_Hello->table();

        BDb::ddlTableDef($tHello, array(
            BDb::COLUMNS => array(
                'id' => 'INT UNSIGNED NOT NULL AUTO_INCREMENT',
                'author' => 'VARCHAR(100) NOT NULL',
                'email' => 'VARCHAR(100) NOT NULL',
                'message' => 'TEXT NOT NULL',
                'created_at' => 'DATETIME NOT NULL',
            ),
            BDb::PRIMARY => '(id)',
        ));
    }
}
comments powered by Disqus