⚠ In case you've missed it we are migrating to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠


Paul Savostin

Member Since 15 Mar 2014
Offline Last Active Feb 22 2017 10:04 PM
-----

#13527 New custom field with text editor

Posted Paul Savostin on 18 December 2015 - 11:23 PM

So I think problem is next - u wanna set custom textfield with texteditor,

but u dont have any other fields with type 'text', so GC doesnt add to the page  js for texteditor plugin like ckeditor(or tinymce)

Solution: if dont have another fields with type 'text' u need add  js by manualy.

Example:

Somewhere in current controller or better in MY_Controller, then u could use this in any controller, set method
 

//this js you should output somewhere on the page after JQuery 
public js_files = arrray();



protected function load_texteditor()
{
    $default_texteditor_path = 'assets/grocery_crud/texteditor';
    $this->js_files[] = $default_texteditor_path.'/ckeditor/ckeditor.js';
    $this->js_files[] = $default_texteditor_path.'/ckeditor/adapters/jquery.js';        
}

//then in current controller u call
$this->load->texteditor();


Custom callback field
 

public function _custom_textfield_with_text_editor($val, $id=NULL)
{
    $value_from_another_table = '';

    //query to database and get value per $id if u need it
    $data_from_db = ...query;

    if($data_from_db) $value_from_another_table = $data_from_db;
                      //custom field name,    //value          //class for texteditor            
    return form_textarea('message', $value_from_another_table,'class="texteditor"');       
      
}

Be careful -  add js only when u dont have other fields with type 'text', otherwise u just use only callback function

This is my solution, mb u find more better :)
 

like Amit say - happy GCing




#13438 Set length digits?

Posted Paul Savostin on 28 November 2015 - 11:13 AM

Its just some kind of bad magic in GC, in version > 1.4.2 this method presents, anyway u can set this method by yourself using this link https://github.com/s.../pull/299/files




#13416 set_relation to the same table

Posted Paul Savostin on 26 November 2015 - 03:51 PM

did u try to add name in ->set_relation?




#13255 Unable to locate the model you have specified: Grocery_crud_model

Posted Paul Savostin on 19 October 2015 - 11:21 PM

I found the solution! carefully check name of Grocery_CRUD_Model, they must be equal in filename and class name!




#12871 How to divide two numbers from a field and insert into the third field

Posted Paul Savostin on 21 July 2015 - 09:50 AM

Friend, you need to write right callback function and method in GC. Check if it working!




#12864 How to divide two numbers from a field and insert into the third field

Posted Paul Savostin on 20 July 2015 - 09:18 AM

 1) Set [Nisbah_Pengeluaran]

 

       $crud->fields(...,'Nisbah_Pengeluaran',...)

                ->field_type('Nisbah_Pengeluaran','invisible');

2) In callback

 

public function _before_insert($post_array)
{

      if(isset($post_array['Jumlah_Pengeluaran'],$post_array['Jumlah_Tandan']))
      {
          $post_array['Nisbah_Pengeluaran'] = $post_array['Jumlah_Pengeluaran'] / ['Jumlah_Tandan'];

      }

      return $post_array;
}




#12849 How to pass more data to the view?

Posted Paul Savostin on 17 July 2015 - 11:33 PM

I can use them in all subclasses that extends this controller, like u see above i can set common properties and many other stuff and in subclasses add some other data or ovveride anything.

One little example, in every controller u should write $crud = new grocery_CRUD(); and here u write this only one time!

believe me this is very useful and i think this is just the best practices :)




#12847 How to pass more data to the view?

Posted Paul Savostin on 17 July 2015 - 10:43 PM

Hi! Lets say u have the base admin controller :

<?php defined('BASEPATH') or exit('No direct script access allowed');

/**
 * Common controller where we use Grocery CRUD
 */
 
class Admin_Controller_GC extends CI_Controller
{
    //GC
    public $crud;

    //current table
    public $table;

    //all data that we will output
    public $data = array();
    
    function __construct()
    {
        parent::__construct();
        
        $this->load->library('grocery_CRUD');
        
        $this->crud = new grocery_CRUD(); //init Grocery Crud
        
        //set theme of Grocery CRUD
        $this->crud->set_theme('datatables');
        
        //common properties - for example u have common fields active users, active posts and so on  
        $this->crud->field_type('active','true_false',array(0 => 'No', 1 => 'Yes'));                
        
          
        
    }
    
    
    
    //output data
    function _example_output()
    {
        //set current table
        $this->crud->set_table($this->table_bd);
        
        //join our additional data with GC data
        $this->data = array_merge($this->data, (array) $this->crud->render());        
        
        //do the output
        $this->load->view('admin/main_tpl', $this->data);
    }
}

So I stay only that stuff u asking about, cause here in this controller we can do many many useful things and I do:)

Then u extend this controller with that u need, add your data like $this->data['some_var'] = $some_data;

Set your database tables like $this->table = 'your_table';

And after all actions with CG api at the end of function just call $this->_example_output();

That's it! ;)




#12833 How to implement a permission system in GroceryCrud?

Posted Paul Savostin on 16 July 2015 - 08:52 AM

Hi! If u have n_n relation so why in first table u have 2 keys? an usual case is table1, related_table_1_to_table_2, table2.

1)You can use custom model, where u extend your query.

2)You can extend  query right in controller, just ($this->db->select ->where.... )

3)Yes to "join" few where condition u just do what u did above, only it could be shorter - $this->grocery_crud->where('field1',$var1)->where('field2', $var2) or using array in where

$this->grocery_crud->where(array('field1' =>  $var1, 'field2' => $var2). But this is CI stuff, look at the docs Database Active Records class in CI documentation




#12791 Save/Update and go back to list button doesn't work

Posted Paul Savostin on 12 July 2015 - 04:31 PM

In firebug i see next
 

TypeError: $(...).tinymce is not a function

So in the from we have three buttons - save (type='submit'), Save and go to the list (type='button') and Cancel (type='button')

Maybe I am wrong but two last buttons work with javascript handle - as we know if any javascript error then script just stop and other will not work.

And first button works because it plain submit form button.




#12721 How can I convert datetime field to "Y-m-d" formate

Posted Paul Savostin on 02 July 2015 - 08:11 AM

Hi! If in database you have timestamp then you dont need to use function "strtotime" - it will be just date('Y-m-d', $your_timestamp_date);

I have misprint in word callback_column - it will be without "S" at the end (You can see list function on the GC site)



Man, learn PHP and GC, I see that you just copy paste and dont thinking at all...




#12696 reuse an image uploaded before.

Posted Paul Savostin on 28 June 2015 - 01:01 PM

What are you waiting for? When somebody write you all code? Try to do smth, write beginning code, if any problems - we help you, but now there is nothing to talk about. Sorry.




#10888 [updated 24/11/2012] Dependent dropdown (library)

Posted Paul Savostin on 15 March 2014 - 11:58 PM

Its My problem

 

i use your same code and database . from first post. only a little change on 'Url'

$crud = new grocery_CRUD();
$crud->set_table('dd_goods');
$crud->set_relation('goods_country', 'dd_country', 'country_title');
$crud->set_relation('goods_state', 'dd_state', 'state_title');
$crud->set_relation('goods_city', 'dd_city', 'city_title');

$this->load->library('gc_dependent_select');
// settings

$fields = array(

// first field:
'goods_country' => array( // first dropdown name
'table_name' => 'dd_country', // table of country
'title' => 'country_title', // country title
'relate' => null // the first dropdown hasn't a relation
),
// second field
'goods_state' => array( // second dropdown name
'table_name' => 'dd_state', // table of state
'title' => 'state_title', // state title
'id_field' => 'state_id', // table of state: primary key
'relate' => 'country_ids', // table of state:
'data-placeholder' => 'select state' //dropdown's data-placeholder:

),
// third field. same settings
'goods_city' => array(
'table_name' => 'dd_city',
//'where' =>"post_code>'167'", // string. It's an optional parameter.
//'order_by'=>"state_title DESC", // string. It's an optional parameter.
'title' => 'id: {city_id} / city : {city_title}', // now you can use this format )))
'id_field' => 'city_id',
'relate' => 'state_ids',
'data-placeholder' => 'select city'
)
);

$config = array(
'main_table' => 'dd_goods',
'main_table_primary' => 'goods_id',
"url" => base_url()."/index.php/main/add_user/",
);
$categories = new gc_dependent_select($crud, $fields, $config);

// first method:
//$output = $categories->render();

// the second method:
$js = $categories->get_js();
$output = $crud->render();
$output->output.= $js;
$this->_example_output($output);

i have face to this problem too and fix for this next -  add default empty <option value="" selected></option> to edit callback method in 

"...   if ($item[$this->fields[$field_info->name]['id_field']] == $value)...." if this condition FALSE

 

string number 163 of this library

By the way special thanks to Victor for this amazing lib