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

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.)

[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:
PHP/Java bridge http://php-java-bridge.sourceforge.net/pjb/
Boost.PHP (C++) https://github.com/moriyoshi/boost.php/wiki
SWIG (C, C++ via wrappers) http://www.swig.org/

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.

Related

Library Authoring Strategies

I'm about 11 months into writing a pretty extensive HTML5-ready video deployment library for PHP. My client is paying me to write this library in exchange for a license to use an implementation of it, which I am also currently writing. I have been basically keeping a huge PHP file (60Kb at this point) that contains all of my object-oriented classes. The system I've built requires in this file on every page, which I imagine would be frowned upon. Don't get me wrong, I'm no newbie when it comes to PHP. I have been writing PHP for about two years now, and used nearly all of its most advanced functions. I would, however, like to improve still, and I believe that my authoring strategies are a weak point for me.
I love jQuery for its authoring simplicity. It makes writing repurposable code so much easier than PHP does, at least for me. I have been using jQuery extensively throughout this After reading this document I felt quite comfortable with the methods that were considered "best practice". Can anyone recall a similar resource which deals with PHP?
My intent here is to learn a better practice for writing PHP, without losing the low-level abilities and jumping over to another library like CodeIgniter. I simply don't like the idea of writing a library based upon another library; I would imagine that my system would leave a much larger footprint and use more resources.
First of all, you can't compare a library to a language. Apples and oranges. Unfortunately there's no single source of ultimate knowledge when it comes to PHP. I can only suggest some reading material I have found quite useful.
PHP-FIG - a set of standards put together by the PHP Framework Interoperability Group (Github link);
autoloading - getting rid of all those include constructs;
Composer - a package manager tracking local dependencies of your projects and libraries;
PHPUnit - a unit testing framework for PHP;
phpDocumentor - use the tags in your comments to clearly document each and every aspect of your code. I personally find Fabien Potencier's Sami for generating automatic documentation more suitable, but that's just a matter of personal preference;
Also, if you like to learn by examples, take a look at these open source PHP libraries that I consider rather well written as far as following best practises goes:
Symfony2 - a full-stack web framework;
Doctrine2 - an object relational mapper for PHP;
KnpMenu - a menu building library;
If you have the resources, I would highly suggest you break down that large file: put every class into its own separate file. Cover the library with unit tests to be sure your code does what it's meant to do.
Edit
#lsmith tweeted about a site called PHP: The Right Way. This is probably the closest you can get to a single document about best practices.

using PHP frameworks (ZF,...) and ORMs (Doctrine,...) as PHP extensions?

Is it possible to use php frameworks (ZF,...) and ORMs (Doctrine,...) as PHP extensions (like Yaf)? What is pros and cons of such method?
I want package third party libraries into a single file (like .dll) so it can be easily deployed. Perhaps some performance improvement yielded?
ZF provide a lot of essential classes, how I make my custom build that ZF be a part of PHP language (like .net class library)?
Copying a lot of .php file in library folder of a php app do not seem intuitive.

UML design tool and implementation language

I'm starting a small project for my programming classes and I need a tool to design an UML model of my application, which then I can implement in PHP or JSP.
I downloaded and installed Argo UML and Poseidon Community Edition, both of them seem pretty neat, but I need to choose one over the othed so if you have any experience with both, which one should be better for me? Is there any other choice I should be aware of?
Secondly I use eclipse IDE and I'm a rookie both in PHP and JSP programming so I really don't care about using one or the other, I would like to work with the one who best integrates with my UML design tool choice. Which one would you recommend me?
I would recommend you Argo UML. It has everything you need for a basic project and unlike Poseidon it's opensource. Also, Poseidon code is based on Argo, so there's not much of a difference if you want to switch from one to another if you require some functionality one has and the other doesn't for future projects.
Poseidon has a version specifically designed to build PHP projects which integrates with Eclipse, but unlike Community Edition it's not free of charge.
Also, consider usign UML integration tools from Eclipse's MDT project http://www.eclipse.org/modeling/mdt/?project=uml2
About the language, I would go for PHP (If you're using Eclipse I guess you've already heard of Eclipse for PHP) but maybe because I'm more fluent on it I see it easier to set up a WAMP/LAMP server and start coding right away, I don't think it really makes much of a difference to use PHP or JSP as long as you use each language's specific tools properly.

PHP framework (cake/smarty): How to use it and when?

Duplicate of
What is a PHP Framework?
and many more
So far, I've been using PHP for small tweaks, mostly with WordPress. What are PHP frameworks? Why do I need them? WHEN do I need them?
Any insight will be helpful. Thanks.
Frameworks are organized groups of code or libraries, built on top of a language to either
Make Common Tasks Easy/Simple
Create a Consistent Way to Develop Applications
Some frameworks are very restrictive (as in it's not easy to do things, unless you do them the 'framework' way), others are looser. I've found Zend's Framework to be a good mix of both, making easy to use single components (for example, you can drop the 'Feed' library into your existing application without needing to rewrite the application the Zend way), or you can use the Zend MVC and Application libraries to for an entire application.
I'd stay away from frameworks that are 'all or nothing'.
From Zend's Framework (restating the above, perhaps more completely):
Zend Framework is an open source framework for developing web applications and services with PHP 5. Zend Framework is implemented using 100% object-oriented code. The component structure of Zend Framework is somewhat unique; each component is designed with few dependencies on other components. This loosely coupled architecture allows developers to use components individually. We often call this a "use-at-will" design.
While they can be used separately, Zend Framework components in the standard library form a powerful and extensible web application framework when combined. Zend Framework offers a robust, high performance MVC implementation, a database abstraction that is simple to use, and a forms component that implements HTML form rendering, validation, and filtering so that developers can consolidate all of these operations using one easy-to-use, object oriented interface. Other components, such as Zend_Auth and Zend_Acl, provide user authentication and authorization against all common credential stores. Still others implement client libraries to simply access to the most popular web services available. Whatever your application needs are, you're likely to find a Zend Framework component that can be used to dramatically reduce development time with a thoroughly tested foundation.
A framework tries to provide all the things that are common to every (or most) projects - html rendering, database access, and so on - in a way that's simple and easy to use.
You would use one to speed development, because you can skip all that stuff, and focus on what's unique to your project. Depending on the one you use, it can also add some security features by automatically escaping data on the way to the database, or to the screen.
I use them in any situation where I don't need something so custom that it's more work to bend the framework to my needs than to create the whole thing from scratch. That's pretty rare.

ActiveScaffold for PHP

Ruby on Rails has a bunch of plugins which extend the normal scaffolding:
Lipsiadmin
Hobo
Streamlined
ActiveScaffold
Does the PHP community have anything similar? phpmyadmin is great, but it doesn't have any way to control the presentation of the data. You always get all of the data in its presentation format. These Rails frameworks are a little more user friendly.
Edit: My original question was not very clear. I'm not looking to compare PHP and Rails. I'm also not looking for an all purpose general framework. I'm looking for something just like the four pieces of software I listed above, but written in PHP. The admin software I listed above generates a crud interface for you based on your configuration. The configuration includes which tables you'd like to show, what operations you can do to the table, and who can see the information. The software does the rest, from writing the SQL to processing the request to generating the interface.
I would look at Zend, CakePHP, CodeIgniter or Kohana. See if they have an addon or plugin that can do it.
The problem with the four pieces of software you listed is that they extend Rails. When you say "PHP," there is nothing to extend in the same sense. (I really doubt you want a PHP module that does this.) You don't need a PHP addon, you need a [framework] addon.
Any of the frameworks I or Jonathan listed are similar to Rails. Kohana in particular has an addon module called Auto Modeler that may do what you need.
have you looked at pear: http://pear.php.net/
It's important to stress the difference between a language and a framework here. PHP is not itself a framework with modules. PHP is a language, like C or Python.
There are several website frameworks that have been written in PHP. The most popular would probably be Drupal though there are several that I've looked at over the last year that seem similarly capable:
CakePHP
CodeIgniter
Joomla!
Symfony
Zend
PhpMyAdmin is not a module or a framework. It is a separate, stand-alone web application for database administration, written in PHP. It won't be a component in any strategy for presentation of data on a website.
Symfony may be a "general framework", but it has scaffolding you can use as a complete application if your needs are simple. You define your model in a YML config file, and can then generate CRUD modules based on this model. The code generation is also customizable by editing other YML config files. All without writing any PHP code. But should the need arise, you have the option to extend the scaffolding with PHP and the complete framework.
See the Symfony docs on code generation.
A framework called ATK also claims a good code:functionality ratio ("An application in 10 lines of code").

Categories