Simple CRUD Generation - php

This is what I have:
An entity-relational schema, modelled for Doctrine 2.0 (in PHP);
The generated database, on a MySQL server.
This is what I want:
A very basic CRUD web-interface to the database, that allows me to (you guessed it!) create, read, update and delete records, with extra credit for implementing CRUD operations on entities and relations instead of records.
Now, I'm terrible at writing web applications myself (read: I'm lazy). Are there any options to generate a CRUD web application from a MySQL database, or from a set of Doctrine entities?
I'd be willing to stop using PHP (and thus rewrite the entities for JPA, Ruby ActiveRecord, etc...) but not MySQL.
I see a lot of similar questions: however, most of these questions have answers that give CRUD operations for in PHP code, or recommend using Doctrine.
An answer such as "There is no such tool, stop being lazy" would also be appreciated.

You should have a look at Grocery CRUD.
Really simple, easy to use /deploy and neat UI.
http://www.web-and-development.com/grocery_crud/
I did a complete web CRUD of my DB in a couple of hours (including additional PHP webservices) Amazing :-)

Symfony does this (at least the 1.x series I am used to). I should think version 2.0 also does, under either Doctrine or Propel (and both of those will work with MySQL).

CakePHP (user guide) takes a database model and generates controllers that do basic CRUD operations for all of your tables. It also includes views and a basic stylesheet.

If your hosting setup can handle Python, the web2py framework offers instant CRUD for a database and a very user friendly (and laziness-friendly) online dev environment. I don't think it's designed to be laid overtop of an existing database, but you can import a CSV file with your database contents. http://www.web2py.com
One of the great things about web2py is that creating custom (public) CRUD pages is also dead easy. In a controller file it's as easy as
form = CRUD.create(db.myTable)
return dict(form = form)
Then in a view file you just add
{{=form}}
And that's it! All of the form creation, input validation, etc., is handled for you. I should also add that the data abstraction layer in web2py is very easy to learn and meshes with mySQL easily. One great thing about it is that web2py performs on-the-fly changes to your datastructure or even migrations from one DB back-end to another.
Not every hosting company knows how to support web2py, but it's easy to deploy on the Google App Engine or with a company like Fluxflex.com

I've been looking for a drop-in admin panel like this too, so far I've 3:
AjaxCrud - http://ajaxcrud.com/
Peek from Code Canyon - http://bit.ly/toKKrB
SQLBuddy - http://www.sqlbuddy.com/
Love to hear any other suggestions!

Ruby on Rails' "Scaffolding" should be exactly what you're looking for...

As according to this answer, I've tried Xataface, which gave me as decent a result as CakePHP or Web2Py would have given me. Am now trying Symfony 2.0 (which is a lot harder then I'd have expected) for the extra credit.

Related

Template engine for single PHP page with structured content?

I'm planning to build a single PHP web page that will contain lots of structured data in nested divs, spans, bootstrap elements etc., like:
Hardware
Notebooks
HP
Apple
Dell
Tablets
Apple
Samsung
Software
Operating Systems
Windows 10
...
The list ist really long with far more than 100 elements. The elements will change from time to time, but the structure will be the same for all elements and sub-elements.
Now, I wonder if plain HTML+CSS is the best way to code this page. As the structure of the elements is always the same, so it would probably be a good idea to use templates. However, I'm not sure if I really should set up a database and some kind of PHP framework like Slim or Laravel/Lumen in order to generate the code. After all, it's just a single page without and routing, forms, login etc. So this might be too much.
Perhaps, a templating engine like Plates could be the answer? But where should I store the data?
What would be your choice for such a use case? Single page with lots of structured data?
Any help is greatly appreciated!
Based on your subject line, I want to clarify something and then suggest a solution.
PHP Components & Composer
State of the art PHP development utilizes Composer to orchestrate component libraries. This could be in the form of a full stack framework or in the form of just a few specific component libraries that solve the problems you have.
Datastores
Your sample shows data with simple hierarchy. Certainly for ease of maintenance a datastore of some type would be helpful. A relational database or a document database will do the job. If that is what you want I'm going to suggest you use a specific ORM or at least a portion of it, and that ORM is Doctrine.
Why Doctrine? Because it supports a number of the most popular open source RDBMS, and it also allows you to use it's DBAL layer without the full ORM, if you just want to implement a few simple queries. With that said, if you have the option of using MongoDB, MongoDB collections support hierarchies very well. A great feature of Doctrine2 is that it has support for MongoDB, which differentiates it from most other PHP ORM's.
The only real reason to go to all this trouble is that you also intend to create an administration tool that will let you maintain your hierarchical data. If you don't, you could just as easily have a script that you include that has the data in PHP array form.
Templating
For templating, my suggestion is that you use Twig. As part of the Symfony components, Twig is both self contained and part of the Symfony full stack framework. It's robust and well designed, and has numerous features (although to be fair, Laravel's Blade has similar features in most cases) and includes support for ESI which could be a great feature for a relatively static page like the one you describe.
Templating in twig, vs writing PHP code to do the same, lets you focus on your markup and avoid introducing a lot of PHP code that will turn your view code into spaghetti.
Components
The important thing is that you can simply use the few components you need to support your application, and you certainly don't need either Laravel or Symfony. Since Symfony began its life as components (and was the foundation for the Laravel project in fact) I'd push you towards the Symfony components, although at the end of the day, you could also utilize parts of Laravel (Blade, Eloquent) in the same way that I'm advocating you use portions of Symfony. Symfony simply is the community and stack I prefer, and has a longer history of being used on a component basis in other projects.
Try out the new minimal Symfony4
Last but not least, the newest version of Symfony (Symfony 4) is really worth looking at for a number of reasons. It essentially is now a micro framework, that comes with the bare minimum of components. They advertise it as 70% smaller than v3.
What differentiates this release is the innovation of Symfony flex with recipes and Composer integration. It is now built to automate a lot of the things that you might otherwise have had to figure out on your own for putting these components together into an application.
Take a look at it and see if it might help you get your application built with minimal components and minimal time spent having to learn how to make things work together.
In summary, I'd suggest you consider:
Symfony Components (You might want a few more depending on your
final solution).
Doctrine2
Twig
Symfony4

drupal create entities programmatically

I use a headless drupal to expose an api for my front app and I have a question regarding the creation and update process of entities in Drupal.
It could be usefull if I could create my entities and my bundles programmatically like writing a php script and run it. And maybe other to alter my sql schemes and entites fields.
I am actually quite noob with drupal (I am used to django and migrations files that works exactly like that). And I want to know of there is an equivalent for it with drupal (7 or 8 ^^).
You can definitely do this in Drupal using the Entity API. I've only dabbled with this in D7, but it does exactly what you want. Of course, it is all done using a Drupal module in hooks, not just a standalone PHP script.
You create your table using hook_schema, and then handle schema migrations using hook_update_N (where N is any number you choose). The entities are defined using hook_entity_info Then you need controllers to manage your entities, fields and field instances that tell Drupal how your entities relate and some information about display.
It is a fairly involved process the first time you run through it. I know it is bad form to link to external resources here, but this subject is fairly dense. I found http://www.zyxware.com/articles/4779/drupal-how-to-create-custom-entity-programatically-in-drupal-7 to be a very valuable resource when I was creating a proof of concept for a project here at work.
Good luck, and let me know how it goes.
If you are using Drupal 8, Drupal Console will help you a great deal. There is a command for generating entities, controllers, forms and many other things.
For Drupal 7 the Entity Construction Kit is the way to go
I have used both these tools sucessfully in production.
There is a lot of boilerplate code to write as you might have noticed from Quint's suggestion.

Which PHP framework should I use for this project?

I have ready numerous posts here on SO about framework1 vs framework2 however it seems to be alot of personal opinions that are one sided. Based on the following can someone tell me which framework would be ideal for my needs?
Build a rich featured API where other sites and devices can use the API to use website features and access it's content.
RSS Feeds with both XML and JSON for jQuery interaction.
Ability to use layouts / templates that are customizable.
Use of plugins so that I do not need to duplicate code.
Database querying with relationships.
GREAT documentation.
Actively supported.
Doesn't REQUIRE command line access.
Easy to manage file uploads and move the files around so only certain users can download them.
Customizable access level so users can have different access levels depending on which project/section they are viewing.
Low overhead usage.
SEO URLS that do not require the '/view','/edit','/add' in the urls (depending on which action you want to do.)
Support for jQuery
There have been a few frameworks I have seen that support some of these but not all. I am currently using CakePHP for one project but do not think it would fit my needs as the database querying can get horrendous. I have heard a little bit about CodeIgnitor however it doesn't seem to easily use templating (maybe I just misunderstood what I read).
If you could tell me which framework you think would be ideal for these needs and why that would be very helpful!
I'll just spamvertize my little framework overview table here. The simple table answers a few of your technical points:
http://matrix.include-once.org/framework/simple
Use the detail/feature view to cherrypick your options.
RSS isn't a standard feature even with the big frameworks, use a PEAR library
templates: all frameworks use them
plugins: depends on your concept of plugins, most frameworks are extensible though
look for "ORM"
GREAT documentation: that would limit you to codeigniter or cakephp
Doesn't REQUIRE command line access: except symfony+cake, few do
file uploads: this isn't a standard feature, but I'd just mix and match a library
Customizable access level: practically all frameworks come with a permission system
Support for jQuery: this is surprising. Prototype seems to be very strong, only half the frameworks use jQuery by default
CakePHP database querying doesn't have to be horrendous. (Though, I remember my first few projects were definitely hard on the database)
With the right optimization, normalization/de-normalization of your data, and a few tweaks here and there (persistent models comes to mind), you can accomplish everything you've inquired about with CakePHP, and keep your database load to a minimum.
That said, if you truly want to move to something else, I'd go with Zend Framework.
Symfony is bloated, (and yes, fanboys, this is still true).
Codeigniter is super lightweight, but you're going to be doing a LOT more work to accomplish your listed requirements. I've spun up two codeigniter applications, both relatively simple, and both took twice the work / twice the amount of new code than if I had gone with say, CakePHP.
A lot of religious fanaticism floating around when you talk about frameworks. But take a look at the documentation of Fat-Free Framework. It just might catch your fancy and requirements.
Before I answer, let me qualify that I'm certified on Zend, a frequent user of CodeIgniter, and daily user (and hater) of Symfony.
Zend's setup, especially if you're doing a small-medium sized site can be ugly. Especially using the data mapper strategy, you're talking a thousand or more lines of codes just for the model setup. CodeIgniter is much better setup-wise, but still not insignificant.
Command-line free --essentially-- knocks out Zend. It's doable, but not fun (see thousand lines of code, above) Built-in user auth isn't nearly as good on CodeIgniter as Zend, perhaps that's a serious knock....definitely no templating there. Symfony is flat-out done because of the addition of /view /edit, etc.
Hate to break it to you, but it seems that many users of all these frameworks are not native English speakers. Forget about Symfony, seems entirely eastern-European based. I'd hate to be a new-to-php user of Zend Framework with all the competing tuts with their assumptions of some semi-complex concepts. There's a reason that Zend's training is expensive and full.... Again, CodeIgniter is not horrible, but still can be frustrating.
Simply because of our extensive use of Jquery and desire to avoid a ton of hack-around, my company has dumped the frameworks altogether. Now setup is purposeful, not for a framework...just build a DAL, assemble classes, build views, and done. Established functions are re-purposed as "plugins" that we actually know and understand. Most interaction is Jquery based Ajax (sometimes XAJAX) which really doesn't take advantage of the frameworks anyway--and fights tooth and nail with Symfony. For those who argue that frameworks force MVC, I have a VP of Development who does that just fine, thank you. Perhaps it's not the right answer for you, but we're glad we went this route. It's saved weeks worth of documentation-hunting.

program/site to generate html form code based on mysql database

I have a mysql databased with many tables and fields. I would like to quickly generate a set of prototype forms based on the mysql database (or create table statements). Anyone have any suggestions? html form code would be great. Full PHP validation and insert updates would be even better. Also Zend framework code would be ideal.
I was looking at mySQL workbench which has an excelent reverse engineering and visual presentaion of databases, but no form generator.
You're looking for a thing called scaffolding.
Scaffolding is a meta-programming method of building database-backed software applications. It is a technique supported by some model-view-controller frameworks, in which the programmer may write a specification that describes how the application database may be used. The compiler uses this specification to generate code that the application can use to create, read, update and delete database entries, effectively treating the template as a "scaffold" on which to build a more powerful application.
Please note that ZF and other PHP frameworks are not MVC frameworks - at least those popular like ZF, Symfony, Kohana, CakePHP etc.
It seems that ZF has built-in support for scaffolding: Zend_Controller_Front_Scaffold.
well, what you want is a little too much specific (not saying that it doesn't exist). maybe this could help you with the boring task of writing the html tags:
http://code.google.com/p/zen-coding/

Is there any php framework which exactly reflect the msaccess

I am fond of dbstructure definition of msaccess which lets defining at once and creating the data entry forms, datatables and reports at once easily.
I have been searching for some framework which would generate the data entry forms, data tables and reports easily. I guess the only thing I need to define is complete datatable structure.
Is there any like that or better one than that?
EDIT:
well i am afraid that PHP frameworks have been limited to programmers only. I would like to extend it with some automated functions like autoform in msaccess which would generate data entry form, auto report for data listing. So that my development time would be again some less. I found doctrine nearly matching my specification but not sure as i haven't fully explored doctrine
Cake offers both "hard" (bake) and "soft" scaffolding, which should be very close to what you want. It's still only meant as a quick proof-of-concept tool and to get you up and running faster so you can concentrate on programming the business logic. It's not meant as a hands-off solution nor to be used in production.
What you seem to be looking for is a database frontend like phpMyAdmin or SQL Buddy, not a PHP framework.
Symfony provides an admin generator that builds all the forms on the fly and it will also update itself when you change your db schema. It is based on doctrine which you say you looked at so that would make things a bit easier for you.

Categories