Skip to content
Louis Lam edited this page Oct 20, 2018 · 6 revisions

Table of Content

  1. Installation
  2. Database Setup
  3. Basic Idea
  4. Quick Notes
  5. Basic Template
  6. LouisCRUD Functions for Creating a Structure
  7. LouisCRUD Functions Used in a Route
  8. Field
  9. Field Type

Quick Notes

URL Pattern:

http://{your hostname}/index.php/crud/{routeName}

Basic Template

<?php
require "vendor/autoload.php";
use LouisLam\CRUD\SlimLouisCRUD;
use RedBeanPHP\R;

R::setup('sqlite:dbfile.db');

$crud = new SlimLouisCRUD();

$crud->add("book", function () use ($crud) {
    $crud->showFields(["id", "title",  "date"]);
});

$crud->run();

LouisCRUD Functions for Creating a Structure

Function Name Description
add($routeName, $closure, [tableName, displayName])
config($closure)
run()
getSlim()

LouisCRUD Functions Used in a Route

Function Name Description
field($fieldName)
find($clause, $data)
findAll($clause)
showFields([...])
hideFields([...])
hideAllFields()
notFound()
addScript($script) Add JavaScript to the page. You code MUST be wrapped by <script> tag.
Event Description
create(closure)
edit(closure)
listView(closure)

Field

Function Name Description
setDisplayName(name) Set the display name
setDefaultValue(val)
setValue(val)
setFieldType(fieldTypeObject)
show()
hide()
setReadOnly(true)
setRequired(true)
addValidator(closure) function ($value, $postData) use ($crud) { }

FieldType

$crud->field("active")->setFieldType(new TrueFalse());
OBject Name Description
new Hidden() Equivalent to <input type="hidden" />
new TextField() Equivalent to <input type="text" />
new Email() Equivalent to <input type="email" />. It is for HTML5 only. Be careful if you would like to use on the old browser.
new Date()
new Password() Equivalent to <input type="password" />
new PasswordWithConfirm()
new IntegerType()
new TextArea()
new CKEditor()
new TrueFalse()
new RadioButton([...])
new Dropdown()
new DropdownManyToOne()
new CheckboxList()
new CheckboxManyToMany()
new Image()
new GoogleMap()

CRUD Object in JavaScript

You can use $crud->addScript(...) to inject JS code to the page.

$crud->addScript("<script> // Your JS Code Here. </script>");
OBject Name Description
crud.addValidator(callback) Add a validator using JavaScript
You can’t perform that action at this time.