A FMT Preferred FileMaker Consultant - Developer
Log in
Hot & Trending on FMT

FileMaker WebViewer Editor - Self Learning Tool for Webviewer Coding

The WebViewer Editor is a self-learning tool for FileMaker web viewer coding.This is a live editor built on FileMaker. When you type something, the web viewer reflects the changes immediately.You can test the CSS property / JS snippets quickly in handy way. In this way, so-called "save"(text editor) - reload (web browser) dance" is not necessary. It's just a FileMaker file, so testing code becomes a record.Your learning process becomes your own coding database.

tutorial videos on YouTube

https://www.youtube.com/watch?v=C6d91FnY2WE
https://www.youtube.com/watch?v=Td7gh0N-Cgs

All of us at FMT would like to thank the author of this video for a very valuable FileMaker developer tool! Get the webviewer editor from this github account.

https://github.com/osamunoda/WebViewerEditor.

SimpleFM v 1.0 – A Composer and Laravel 5 friendly PHP package for interacting with hosted FileMaker data

L5SimpleFM is a PHP package used to provide a simple, readable, declarative syntax for accessing data hosted on a FileMaker Server from a composer-friendly PHP project. The package also has a ServiceProvider class which allows it to be easily pulled into a Laravel 5 project.

The L5SimpleFM package is now available as a 1.0 release on github. It can also be installed from packagist via composer.

A brief example:

Selecting the first 10 records from a layout Inventory with the status “active” would look like:


use L5SimpleFM\FileMakerModels\BaseModel;

// The model class
class Inventory extends BaseModel
{
    protected $layoutName = 'Inventory';
}

// The controller
use App\FileMakerModels\Inventory;

class InventoryController extends Controller 
{

    protected $inventory;

    public function __construct(Inventory $inventory)
    {
        $this->inventory = $inventory;
    }

    public function getActiveInventoryItems(Request $request)
    {
        $returnCount = $request->input('count');
        $result = $this->inventory->findByFields(['status' => 'active'])->max($returnCount)->executeCommand();
        $records = $result->getRows();
        return compact('records');
    }

}

The tool is a wrapper around the Soliant Consulting tool SimpleFM. SimpleFM handles the actual sending and receiving of data to and from FileMaker server, L5SimpleFM creates a human readable syntax and allows for the creation of Model classes for an MVC project pattern. A simple example Task project I created using L5SimpleFM can be found here on github.


 

The need

Recently I started working on a web project for Skeleton Key that used FileMaker as a back end database. I had worked with the FileMaker PHP API in the past and while it was useful, it had a couple of drawbacks that made me want to explore other tools. Namely:

  • It contains code that has been deprecated by PHP which causes errors when running from a modern version of PHP.
  • It is not PSR friendly which makes it harder to work with a modern PHP framework (e.g. Laravel which is my favorite framework).

Ultimately, I tried to include the FileMaker PHP API into a Laravel project via composer classmap and ran into so many roadblocks for the simplest database call that I scrapped the idea of trying to fit it in.

From there I explored a couple of other tools as far as accessing FileMaker from a PHP framework. I explored Goya’s RestFM and Soliant Consulting’s SimpleFM. Both are amazing tools and I can see using both of them in various kinds of applications.

In the end, I chose SimpleFM for a number of reasons, but the most important reason was that I wanted to be able to point my project to any FileMaker Server, not just the one I configured RestFM for.

Wrapping SimpleFM

I pulled SimpleFM into my project and started using it directly. It’s fairly straight forward to use if you’re familiar and comfortable with FileMaker’s XML web publishing syntax, but the look and feel of the code I was writing wasn’t as readable as I would like:

    

    // A contrived example:
    public function index(Request $request)
    {
        $returnCount = $request->input('count');

        // This would normally be included in some global file accessible by any php page that will use the adapter
        // I'm showing this here with the credentials inline to show the full picture.
        $hostConnection = new HostConnection('127.0.0.1', 'L5SimpleFMExample', 'web_user', 'webdemo!');
        $this->adapter = new Adapter($hostConnection);

        // within an InventoryController
        $this->adapter->setLayoutName('Inventory');
        $commandArray = [
            'status' => 'active',
            '-max' => $returnCount,
            '-find' => null,
        ];

        $result = $this->adapter->setCommandArray($commandArray)->execute();
        $records = $result->getRows();

        return compact("records");
    }

The action being performed is defined by the data rather than a class. There isn’t an issue with this, it’s a very transparent way of interfacing with FileMaker XML web publishing, but keeping it this way makes the code less portable. Rather than coding common commands into data each time I want to interact with FileMaker in my application I would prefer to structure those common commands into a class and inject that class into my code as needed.

This is how L5SimpleFM started. The construction and instantiation of the host connection and adapter were moved out to a ServiceProvider for easier Laravel integration.

Note: This is the standard ServiceProvider for L5SimpleFM. You do not have to code this, you only need to add the service provider reference to your laravel `config/app.php` file.


use Illuminate\Support\ServiceProvider;
use L5SimpleFM\L5SimpleFM;
use Soliant\SimpleFM\Adapter;
use Soliant\SimpleFM\HostConnection;

class L5SimpleFMServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->constructAndBindL5SimpleFM();
    }

    protected function constructAndBindL5SimpleFM()
    {
        $this->app->bind('L5SimpleFM\Contracts\FileMakerInterface', function ($app) {
            // credentials are pulled from the laravel `.env` file.
            $username = env('FM_USERNAME');
            $password = env('FM_PASSWORD');
            $host = env('FM_HOST);
            $database = env('FM_DATABASE');

            $hostConnection = new HostConnection($host, $database, $username, $password);
            return new L5SimpleFM(new Adapter($hostConnection));
        });
    }
}


Common commands could be fired from a L5SimpleFM class method:


use L5SimpleFM\Contracts\FileMakerInterface;
use Illuminate\Http\Request;

class InventoryController extends Controller
{

    protected $fm;

    public function __construct(FileMakerInterface $fm)
    {
        $this->fm = $fm;
    }

    public function index(Request $request)
    {
        $max = $request->input('max');
        $skip = $request->input('skip');
        $result = $this->fm->setLayout('Inventory')->findAll()->max($max)->skip($skip)->executeCommand();
        $records = $result->getRows();
        return compact('records');
    }
}


FileMaker Models

This worked but seemed a bit disorganized within an MVC framework. Any time I built up and fired a command I was dealing with one context/entity within my database at a time. The next logical step in organizing the tool was to use it to create FileMaker Model classes.

I created a BaseModel abstract class that acts as a map between the L5SimpleFM service and whatever new model you extend from the BaseModel.

Now a FileMaker model class can be created that clearly defines an entity within the Laravel project:


use L5SimpleFM\FileMakerModels\BaseModel;

class Inventory extends BaseModel
{
    protected $layoutName = 'Inventory';
}


The layout name specified sets the context for all commands fired from the model. Now I can inject the new model into my controller and clean up my command just a bit:


use App\FileMakerModels\Inventory;
use Illuminate\Http\Request;

class InventoryController extends Controller
{
    protected $inventory;

    public function __construct(Inventory $inventory)
    {
        $this->inventory = $inventory;
    }

    public function index(Request $request)
    {
        $max = $request->input('max');
        $skip = $request->input('skip');
        $result = $this->inventory->findAll()->max($max)->skip($skip)->executeCommand();
        $records = $result->getRows();
        return compact('records');
    }
}

The L5SimpleFM service class can still be used directly via the FileMakerInterface which is ideal for building small services that interact with FileMaker but don’t necessarily need a model class, but for cases where creating a dedicated model makes better sense the BaseModel abstract can be used.

Using the package

The L5SimpleFM package is now available as a 1.0 release on github. It can also be installed from packagist via composer.

The tool is open source so feel free to explore.

If you have any feedback you can post questions to github, shoot me an email at This email address is being protected from spambots. You need JavaScript enabled to view it., or post to me on twitter @cschmitz81.

Christopher Schmitz is a Certified Developer at Skeleton Key.

About Skeleton Key

Skeleton Key helps turn complex, complicated, and outdated systems into true information platforms. Our team of consultants and developers do this by developing custom-fit software tools and reporting dashboards that help businesses find, use, and understand their data, freeing them to focus on and grow their core business.

In addition to custom databases and applications, we also provide training and coaching for getting the most out of your existing systems and understanding your unruly data. Skeleton Key is an open-book management company and active player of the Great Game of Business.

Sync FileMaker and WordPress in 5 Simple Steps

360Works MirrorSync can sync data between FileMaker Server and SQL databases which makes platforms like WordPress, powered by PHP and MySQL, an ideal candidate.

The objective of this content is to provide you with a comprehensive overview of the steps you need to set up this synchronization, based on the video tutorial we have available. The video is embedded at the bottom of this article and will provide you with additional details and visuals you may need.

If this is your first time using MirrorSync, we have documentation you may want to review before getting started with setting up your first sync:

System Requirements

Basic and Advanced Setup Topics

When you are ready to begin, the following 5 steps will guide you in a successful configuration of a FileMaker and WordPress sync using MirrorSync.

Step 1: Prepare your FileMaker database

To begin you must have your FileMaker database hosted on FileMaker Server. You can either create a new FileMaker database or use an existing database. Please note, it is best to follow this guide with a FileMaker database that has no existing WordPress tables. During the course of this setup, MirrorSync will be adding new tables to the FileMaker database to store the WordPress tables.

Note: It is possible to sync with existing WordPress tables, but it is easiest to let MirrorSync set the new tables for you. Please contact us if you would like to use existing tables in your synchronization, as there are additional steps involved.

Step 2: Begin the MirrorSync setup using the configuration utility

MirrorSync has always been known for its simple setup process. You will use this signature guided setup utility to configure. In this guide, you can begin by setting up the Hub as the MySQL database where your WordPress data is stored. The Spoke will be set up as the FileMaker database. This is the model you will choose if you are mainly working in WordPress, and simply want to pull data into FileMaker. Alternatively, if you mainly work on the FileMaker end you can reverse this setup and set your MySQL database up as the Spoke instead. If you have questions about this, please contact us.

Choose WordPress as your MySQL database

Next, the configuration tool will guide you in 3 simple steps for copying the MirrorSync table, scripts, and layout into your FileMaker database.

3 Step Guided MirrorSync Utility

After these steps are completed, the configuration utility will prompt you to create sync layouts for your FileMaker database. Because you are pulling in tables from MySQL, you will skip this step.

Do not do anything with the FileMaker tables when prompted. MirrorSync will add these for you.

As we mentioned previously, you should not have any existing WordPress tables in your FileMaker database. MirrorSync will create the tables for you.

Do not do anything with the FileMaker tables when prompted. MirrorSync will add these for you.

Step 3: Add Modification and Creation Timestamps for MySQL

By default, WordPress does not have a Modification Timestamp on all tables. When you arrive at the MySQL configuration window, create a new Modification Timestamp field and a new Creation Timestamp field for all tables.

Add Modification and Creation Timestamps to the MySQL database

Step 4: Set up Foreign Key Mapping

At this part of the configuration, MirrorSync needs to know what the foreign keys are between the tables in your MySQL database. So let's fill MirrorSync in on the action!

In the video tutorial, Jesse explains that he accessed the list of foreign keys needed from the database schema documentation on the WordPress website. You can follow along with him in this portion of the setup video to breeze through this step. If you are only following along with the 5 written steps in this article, here is a list of the foreign keys you will need:

wp_commentmeta:
comment_id -> wp_comment

wp_comments:
user_id -> wp_user
comment_post_ID -> wp_posts

wp_postmeta:
post_id -> wp_post

wp_posts:
post_author -> wp_user
post_parent -> self

wp_term_relationships:
object_id -> wp_post
term_taxonomy_id -> wp_term_taxonomy

wp_term_taxonomy:
parent -> self
term_id -> wp_term

wp_usermeta:
user_id -> wp_user

Foreign Key Mapping for WordPress

Step 5: Paste tables. Paste scripts. Sync!

After you confirm the relationships are correct, MirrorSync will copy the tables to your clipboard and you will paste this into your FileMaker database. This is the part we mentioned earlier, where MirrorSync will create the tables for you with the metadata for the fields already properly configured with the MySQL data.

Next, you can go back into the MirrorSync configuration utility and copy the script steps. You will notice that MirrorSync has already written the entire sync script for you, all you need to do is paste the script steps into your FileMaker database under the 'MirrorSync' script.

FileMaker Database Setup. Copy to your clipboard and paste.

MirrorSync has written the script for you.


After you paste in your script steps, you will run the sync and you are ready to go!

We hope you enjoyed this article. If you are ready to begin syncing FileMaker with WordPress, visit the MirrorSync page to purchase your FileMaker Server to SQL database configuration or email us at This email address is being protected from spambots. You need JavaScript enabled to view it. for a 14-day trial of this configuration.

Subscribe to this RSS feed