Home » Php » php gtk – any real MVC library in PHP (for GUI apps)

php gtk – any real MVC library in PHP (for GUI apps)

Posted by: admin July 12, 2020 Leave a comment


I’m wondering if there are any abstraction frameworks for one of the PHP gui libraries. We have PHP-GTK, a PHP/Tk interface, and seemingly also PHP-QT. (Not tried any.)

I know that writing against the raw Gtk+ interface in Python is just bearable, and it therefore seems not very enticing for PHP. I assume it’s the same for Qt, and Tk is pretty low-level too. So I’m looking for something that provides a nicer object structure atop any of the three. Primarily TreeViews are always a chore and php-gtk callbacks are weird in PHP, so I’d like a simplification for that. If it eases adding the GUI/View atop my business logic without much control code, that might already help.

And so since GUI apps are an area where MVC or MVP would actually make sense, I’d like to know if any library for that exists.

Still open for answers.
(There will probably be a second bounty round. It’s an uncommon topic, so needs more research.)

How to&Answers:
[Not an answer. Just wanted to remove this from the question, as it’s only related, not a solution.]

There is the PHP interface preprocessor. However it is very simple and low-level. It provides an output interface for Gtk, as well as ncurses, but also PDF or XHTML serialization. Which is interesting, as it’s close to real MVC constructs in allowing to exchange the View for different backends without adapting the Controller even. But then it only provides the basic widgets, and not a whole lot of simplifications. Thus I only consider it related to my original question. So, a side note.


Have you tried WinBinder? Not exactly MVC related, but a very nice extension to create gui based programs in PHP.


Now there are a few options that work on newer versions of php. Some of these do not provide you with MVC out of the box, but you can use them to make GUI application in php.

There is the very easy to use php-gui. It does not require any special php extentions, you can just install it with composer like any other php library or framework you depend on. It is geared toward simple, standard user interfaces.

If you need to make something very custom and graphically advanced, and are willing to use an API that was designed to make games in C (or if you want to make a game in php), you could use OpenGL via SDL via FFI via ffi-sdl. It currently (as of 6/1/2020) requires php 7.4 or greater as it uses the recently added ffi feature of php. Even though this relies on the ffi extension, php-ffi is still easy to add to your project. It is still sort of extensionless (like php-gui) because there are no extensions tailor made just for this for it to work. Unlike some other extensions, there is not much chance ffi will not be maintained since it is a feature of php itself. Most people will just need to add ff-sdl to their project using composer, and possibly enable ffi in their php.ini.

I just learned you could also use PeachPie. It allows you to compile and run php code for/on .NET, so you would gain access to .NET GUI libraries, including MVC ones.


I really doubt that you’ll find anything like that ready to use OotB. PHP GUI programming has totally failed few years ago.

What you can do however, is use some kind of bridge to interface decent MVC from another language. Which PHP you have following choices:


http://phpketchup.isgreat.org/ PHPKetchup is a new project in planning stage. There isn’t any code available for now (also seems intended commercial, not open source). It was announced as framework atop PHP-GTK. There is a conception document which explicitly lists the goal as designing a MVC framework.

However it seems like they take inspiration from CodeIgniter and mostly the common PHP framework structure. The focus seems not to lie on integrating PHP-GTK with the application logic, but mostly to provide a database interface as model and a thin Gtk interface for the View.

MVC Architecture:
We will design and implement Model-View-Controller (MVC) architecture for the PHP-GTK framework. SQLite will be used for Model. PHP-GTK functions and Glade files will be integrated in View after removal of HTML, CSS and Javascript. Controller will be modified accordingly to work with the newly created View.

So it might just be MVC in name and organization, but one of the diagrams mentions “PHP-GTK functions addition” and there are further hints of object-structured Gtk helpers.