Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Error in the server
#1

[eluser]Reza Valinezhad[/eluser]
I wrote a custom library. It works fine on my local system, but it causes error on the server.

This is the code of the library:

Code:
class MY_Table extends CI_Table {

    var $_classes = array();
    var $_ids = array();
    
    function MY_Table()
    {
    }
    
    function add_row_id($id)
    {
        $this->_ids[] = $id;
    }
    
    function add_row_class($class)
    {
        $this->_classes[] = $class;
    }
    
    private function callback_function($match) {
        static $index = 0;
        
        $id = isset($this->_ids[$index]) ? ($this->_ids[$index] ? " id='{$this->_ids[$index]}' " : "") : "";
        $class = isset($this->_classes[$index]) ? ($this->_classes[$index] ? " id='{$this->_classes[$index]}' " : "") : "";
        
        $index++;
        
        return $match[0] . $id . $class;
    }
    
    function generate($table_data = NULL)
    {
        $html = parent::generate($table_data);
        
        $html = preg_replace_callback('%<tr%', array($this, 'callback_function'), $html);
        
        return $html;
    }

}

In the server it says:
Code:
Fatal error: Call to undefined method CI_Table::add_row_id() in ***/contents.php on line 18
#2

[eluser]Sudz[/eluser]
Can you post line number 18 of contents.php file
#3

[eluser]Reza Valinezhad[/eluser]
Line 18 is

Code:
$this->table->add_row_id(0);

The whole code
Code:
$tmpl = array('table_open'=>'<table class="normal" style="min-width:100%">');
    $this->table->set_template($tmpl);
    $this->table->add_row_id(0);

It works fine as expected in localhost, but causes error in the server.
#4

[eluser]Sudz[/eluser]
Have you uploded MY_Table library on the server
and load that library in your controller or in config file?
#5

[eluser]Reza Valinezhad[/eluser]
Yes. The code is absolutely same.

I used this line in the controller:
Code:
$this->load->library('Table');

but I used it in the view. (line 18 is in the view).
#6

[eluser]Sudz[/eluser]
Your library classes should be placed within your application/libraries folder,

Try this to load your library
Code:
$this->load->library('Table');

And call class method using this code
Here my_table must be in small case.
Code:
$this->table->add_row_id(0);


You Class name must be Capital and file name in small case
and both name must be same.

Have you set this in your application/config/config.php
$config['subclass_prefix'] = 'MY_';
#7

[eluser]Sudz[/eluser]
I think you have not included this in your library
Code:
public function __construct()
    {
        parent::__construct();
    }
#8

[eluser]Reza Valinezhad[/eluser]
I checked everything. All is set as you told. I replaced MY_Table()function by __construct(), but the error not solved. I just don't know why it works on localhost and not work on server. is there any php settings or something like that?
#9

[eluser]Sudz[/eluser]
[quote author="Reza Valinezhad" date="1304187579"]Yes. The code is absolutely same.

I used this line in the controller:
Code:
$this->load->library('Table');

but I used it in the view. (line 18 is in the view).[/quote]


Load in The controller then try it
#10

[eluser]InsiteFX[/eluser]
If you use your own template and not the default, you have to specify the whole table template code!
I place it in a MY_Controller for CRUD operations!
Code:
$tmpl = array (
    'table_open'         => '<table border="0" cellpadding="4" cellspacing="0">',

    'thead_open'         => '<thead>',
    'thead_close'        => '</thead>',

    'heading_row_start'  => '<tr>',
    'heading_row_end'    => '</tr>',
    'heading_cell_start' => '<th>',
    'heading_cell_end'   => '</th>',

    'tbody_open'         => '<tbody>',
    'tbody_close'        => '</tbody>',

    'row_start'          => '<tr>',
    'row_end'            => '</tr>',
    'cell_start'         => '<td>',
    'cell_end'           => '</td>',

    'row_alt_start'      => '<tr class="alt">',
    'row_alt_end'        => '</tr>',
    'cell_alt_start'     => '<td>',
    'cell_alt_end'       => '</td>',

    'table_close'        => '</table>'
);

$this->table->set_template($tmpl);

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB