multi-language
- Single Page
Posted 23 January 2012 - 09:07 AM
and thanks for multi-language
feature that You add in last version
but I have a question ?
can I after setting the table get its fields as a return like
$crud->set_table('users');
$columns=$crud->get_columns('users');
and get the columns as array to translate it like
for ($i;$i<$columns.lenght;$i++)
$crud->display_as($columns[$i],$users_arabic[i]);
//$users_arabic is an array of translated columns name
2- is there any function that help me to translate the columns name (from xml as example)
thanks
Posted 23 January 2012 - 09:09 AM
<?php foreach($columns as $column){?>
but can I use it in the controlers??
Posted 23 January 2012 - 19:28 PM
I see in the list.php $columns
<?php foreach($columns as $column){?>
but can I use it in the controlers??
[/quote]
Actually is pretty simple: You can do it with a little hack from your controller. For example:
function full_example()
{
$crud = new grocery_CRUD();
$table_name = 'customers';
$crud->set_table($table_name)
->set_subject('Customer')
->columns('customerName','contactLastName','phone','city','country','creditLimit');
foreach($this->db->query("SHOW COLUMNS FROM $table_name")->result() as $db_field_type)
{
$crud->display_as($db_field_type->Field, $users_arabic[$db_field_type->Field]);
}
$crud->fields('customerName','contactLastName','phone','addressLine1','city','country','creditLimit');
$crud->required_fields('customerName','contactLastName');
$output = $crud->render();
$this->_example_output($output);
}
or something even more simple than that:
function full_example()
{
$crud = new grocery_CRUD();
$table_name = 'customers';
$columns = array('customerName','contactLastName','phone','city','country','creditLimit');
$crud->set_table($table_name)->set_subject('Customer')->columns($columns);
foreach($columns as $column)
{
$crud->display_as($column, $users_arabic[$column]);
}
$crud->fields('customerName','contactLastName','phone','addressLine1','city','country','creditLimit');
$crud->required_fields('customerName','contactLastName');
$output = $crud->render();
$this->_example_output($output);
}
You can choose whatever method you like ;-)
As for your second question there is not such a thing but you can hack the code and do it by your own. The field data names is taken at application/models/grocery_model.php at line 246 with name [i]get_field_types_basic_table[/i], you can see it at: https://github.com/scoumbourdis/grocery-crud/blob/master/application/models/grocery_model.php . With combination also with the set_model function ( http://www.grocerycrud.com/crud/function_name/set_model ) it will make it even more easy for you to do it without hacking the grocery CRUD core.
Posted 25 January 2012 - 08:26 AM
Posted 28 January 2013 - 10:47 AM
function full_example()
{
$crud = new grocery_CRUD();
$table_name = 'customers';
// Using CI list_fields that returns an array containing the field names
$columns = $this->db->list_fields($table_name);
$crud->set_table($table_name)->set_subject('Customer')->columns($columns);
foreach($columns as $column)
{
$crud->display_as($column, $users_arabic[$column]);
}
$crud->fields('customerName','contactLastName','phone','addressLine1','city','country','creditLimit');
$crud->required_fields('customerName','contactLastName');
$output = $crud->render();
$this->_example_output($output);
}
You can also store arabic translation in the database in the meta-data fields and use $this->db->field_data()