Ryan Schafer
Ryan Schafer

Reputation: 241

Easiest way to create a CRUD with PHP

I'm new to PHP (used to Python) and I've been instructed to create something that will allow users to CRUD entries. I was originally going to use a textarea field and sort by which numbered row they were, but I realized that if a user deleted a row, that it would screw up all the UIDs for the whole system.

So now here I am, several hours into the project and trying to figure out what's the best way to create something which A) allows multiple rows of data B) allows this information to be deleted or updated C) allows additional rows to be added D) shows all the rows available (this can be scrollable, so that it all doesn't display at once)

Database is MySQL

Are any of these easy to integrate? I don't know quite how much access I have to the server that this is running on.

Upvotes: 1

Views: 1762

Answers (5)

romaninsh
romaninsh

Reputation: 10664

Some PHP frameworks come with built-in CRUD, but since OP didn't ask for any specific framework, then my answer recommends a framework-agnostic CRUD.

Agile UI is an open-source PHP UI component library containing CRUD, Grid, Form, Menu and many other visual elements you can use out-of-the box.

15 lines of PHP, (no HTML and no boilerplate code) is enough to build this UI:

enter image description here

Here is full code:

require 'vendor/autoload.php';
$app = new \atk4\ui\App('My App');
$app->initLayout(new \atk4\ui\Layout\Admin());

$db = \atk4\data\Persistence::connect($DSN);

class User extends \atk4\data\Model {
    public $table = 'user';
    function init() {
        parent::init();

        $this->addField('name');
        $this->addField('email', ['required'=>true]);
        $this->addField('password', ['type'=>'password']);
    }
}

$app->layout->add(new \atk4\ui\CRUD())
    ->setModel(new User($db));

You'll need to also run: composer require atk4/ui but that's it.

Upvotes: 3

dylanized
dylanized

Reputation: 3855

I'm looking for a drop-in admin like this too, here's one I found so far:

http://ajaxcrud.com/

Upvotes: 0

Adrian Cornish
Adrian Cornish

Reputation: 23858

I recommend using the yiiframework. It design is pythonesque like. The Gii generator that comes with Yii will read you DB tables and create all the necessary CRUD code for some simple editing.

http://www.yiiframework.com/

Upvotes: 0

Matt Stauffer
Matt Stauffer

Reputation: 2742

It's a bit overkill, but you can very quickly get a basic and flexible CRUD up and running by installing CodeIgniter and then GroceryCRUD.

Upvotes: 3

Mike B
Mike B

Reputation: 32145

Consider looking at a framework that comes with prototyping or scaffolding support like CakePHP. Besides PHPMyAdmin, that's probably the fastest way of getting CRUD functionality to work with an existing datastore.

Upvotes: 2

Related Questions