# xCRUD Main Methods
# get_instance()
Returns the main object xCRUD. This is a static method and can be called anywhere, indefinitely.
Parameters:
instance_name - [Optional] Assign an identifier to the instance being created.
$xcrud = Xcrud::get_instance();
You can create multiple instances of xCRUD on one page (for example, to work with multiple tables):
$xcrud1 = Xcrud::get_instance();
$xcrud2 = Xcrud::get_instance();
Next, for each instance you can use different methods.
Multiple Instances
If you want to get the same instance in different functions/file (for expample, in controller an view), you must specify instance name. Calling an instance by name you will always get the same instance. See Below
// controller.php
$xcrud = Xcrud::get_instance('MyInstance');
$xcrud->table('users');
// view.php
$xcrud = Xcrud::get_instance('MyInstance');
$echo xcrud->render();
# table()
Sets the table name from which data will be loaded. This method is mandatory.
Parameters:
table_name - The name of the table.
$xcrud->table('my_table');
You can also load a table from another database.
Important
xCRUD needs at least one primary or unique field in your table. If not, you will get an error. The best practice is to use primary autoincrement column in every table. This was done to prevent losing of your data. Xcrud can't work with complex (combined) primary index.
# connection()
Creates a connection for the current instance of xCRUD.
Parameters:
username - database user username `\n password - database user password
username - database user username
password - database user password
remote_table -
host] - [Optional] database host. Defaults to 'localhost'
encoding - [Optional] connection character encoding. Defaults to 'utf-8'
$xcrud2->connection('username','password','remote_table','localhost','utf-8');
This method is rewriting connection settings from configuration file for current instance
# language()
Sets interface language. Its better to set the language in the configuration file. Use this method only if you really need dynamic language switching.
Parameters:
lang_code - [Optional] Language code. Defaults to 'en' (English).
$xcrud->language('en'); // will load en.ini lang file from languages folder
# set_lang()
Allows you to replace existing language translator in the current instance. The best way is to customize the lang file. Do not create new variables with set_lang(), put them in language file.
Parameters:
lang_var - translate -
# render()
Displays your data. While this method is not called, xCRUD takes no action, the database is not connected, this saving system resources (especially critical for large data).
$out = $xcrud->render();
// some code...
echo $out;
// or
echo $xcrud->render();
// or
echo $xcrud;
You can start xcrud not only from grid (by default), and always from create, edit or details screen:
$xcrud->render('create'); // add entry screen
$xcrud->render('edit', 12); // edit entry screen, '12' - primary key
$xcrud->render('view', 85); // view entry screen, '85' - primary key
Remember that the render () method must be called last, it just returns the data for output, and all the methods declared after (for the current instance) will not be applied.