1. Go to this page and download the library: Download simple-crud/extra-fields library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
simple-crud / extra-fields example snippets
use SimpleCrud\Fields\File;
//Register the field
File::register($simpleCrud);
//Configure the directory to upload the files
$simpleCrud->setConfig(File::CONFIG_UPLOADS_PATH, '/path/to/uploads');
//You can also configure the File field
$simpleCrud->user->file
->setConfig('directory', '/path/to/uploads') //custom directory used instead the default File::DIRECTORY
->setConfig('relative_directory', '/images') //custom subdirectory (by default is /{table_name}/{field_name})
->setConfig('save_relative_directory', true) //whether save the relative_directory in the database instead only the filename (false by default)
//Get the data from the serverRequest
$data = $request->getParsedBody();
$files = $request->getUploadedFiles();
//Create the new user
$user = $simpleCrud->user->create([
'name' => $data['name'],
'email' => $data['email'],
'file' => $files['avatar'],
]);
//Save the data
$user->save();
//Get the avatar file
echo $user->file; // /user/avatar/image.jpg;
use SimpleCrud\Fields\Slug;
//Register the field
Slug::register($simpleCrud);
//Create the new article
$title = 'Hello world'
$article = $simpleCrud->articles->create([
'title' => $title,
'slug' => $title,
]);
//Save the data
$article->save();
//Get the slug
echo $user->article->slug // hello-world
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.