⚠ In case you've missed it, we have migrated 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 is an archived forum. ⚠

  •     

profile picture

Fill change_field_type with data



bianconeri

bianconeri
  • profile picture
  • Member

Posted 08 May 2013 - 13:36 PM

Hy,

 

How do I fill a array with data at database?

Example:

->change_field_type('id', 'enum', array('here I want fill with a select '));


victor

victor
  • profile picture
  • Member

Posted 08 May 2013 - 19:24 PM

$enum = array();

$result = $this->db->get('your_table')->result_array();
if (!empty($result))
{
foreach ($result as $item)
{
$enum[] = $item['name'];
}

$crud->change_field_type('id', 'enum', $enum);
}


bianconeri

bianconeri
  • profile picture
  • Member

Posted 11 May 2013 - 16:05 PM

Thanks my friend.

My form update, edit and add are ok at table content

I am calling callback_after_update('insert') and my function



function insert() {
        $data = array(
            'id' => '1',
            'tabela' => 'pages',
        $this->db->insert('pages', $data);
        return TRUE;
    }

But, doesnt insert any data this table.

davidoster

davidoster
  • profile picture
  • Member

Posted 12 May 2013 - 06:28 AM

Can you post your controller's code?


bianconeri

bianconeri
  • profile picture
  • Member

Posted 13 May 2013 - 01:46 AM

This my controller



<?php
 
class Test extends MX_Controller {
 
    function __construct() {
        parent::__construct();
        $this->load->library('grocery_crud');
    }
 
    function _output($output = null) {
        $data = array(
            'output' => $output
        );
        echo Modules::run('grocery', $data);
    }
 
    function index() {
        
    }
 
    function pages() {
 
        $crud = new grocery_CRUD();
 
        $crud->set_table('pages')
                ->set_subject('Pages')
                ->columns('title', 'status', 'update')
                ->unset_add_fields('update')
                ->unset_edit_fields('update')
                ->callback_after_update('insert_update')
        ;
 
        $output = $crud->render();
        $this->_output($output);
    }
 
    function insert_update() {
        $data = array(
            'id' => '1',
            'comment => 'Update');
       $this->db->insert('update', $data);
        return TRUE;
    }
 
}

davidoster

davidoster
  • profile picture
  • Member

Posted 13 May 2013 - 10:21 AM

The proper way of defining a callback is this,

 

$crud->callback_after_update(array($this, 'your_function'));

 

and then you need to have your callback function like this,

 

function your_function($post_array,$primary_key)
{

}

 

Make sure you always read the manuals.


victor

victor
  • profile picture
  • Member

Posted 13 May 2013 - 14:39 PM

oh,yes! read the manual! and you will have good skills for GC. Sorry for my sarcasm, but there are too many questions as you have asked.

bianconeri

bianconeri
  • profile picture
  • Member

Posted 16 May 2013 - 12:38 PM

Sorry everyone.

I thought don't need set params at callback.

victor

victor
  • profile picture
  • Member

Posted 16 May 2013 - 15:50 PM

don't worry! good luck!

bianconeri

bianconeri
  • profile picture
  • Member

Posted 19 May 2013 - 01:07 AM

Hy again, 
 
My struture:
 
- modules
  - web
    - controlllers
      example.php
  - grocery_crud
       all files.
 
When I test by module grocery_crud this work very well.
 
I want load module grocery_crud at module web/controllers.
 
This my example.php
 
 
<?php
 
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
 
class Example extends MY_Controller {
 
    function __construct() {
        parent::__construct();
         
 
    }
 
    function _output($output = NULL) {
        $data = array(
            'output' => $output
        );
        echo Modules::run('templates/example', $data);
    }
 
    function index() {
        $this->_output((object)
                array('output' => '', 'js_files' => array(), 'css_files' => array()));
    }
 
    function example() {
        $grocery = new grocery_CRUD();
 
        |  my set grocery_crud  |
        $output = $crud->render();
        $this->_output($output);
    }
 
}

davidoster

davidoster
  • profile picture
  • Member

Posted 19 May 2013 - 07:30 AM

Are you using HMVC? Something else?

I haven't use them before so I woudln't know how to help you.


bianconeri

bianconeri
  • profile picture
  • Member

Posted 19 May 2013 - 15:47 PM

Yes I use HMVC.
Ok, thanks for help at moment  David.