CodeIgniter Forums
HTML Table Class new error! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: HTML Table Class new error! (/showthread.php?tid=74057)



HTML Table Class new error! - videoproc - 07-16-2019

Hello!

Please help! Added lines to controller method:
PHP Code:
$table = new \CodeIgniter\View\Table();

$data = array(
 
       array('Name''Color''Size'),
 
       array('Fred''Blue''Small'),
 
       array('Mary''Red''Large'),
 
       array('John''Green''Medium')
);

echo 
$table->generate($data); 

error:  Class 'CodeIgniter\View\Table' not found

What use to add?


RE: HTML Table Class new error! - mboufos - 07-16-2019

check here
https://www.codeigniter.com/user_guide/libraries/table.html

load the library in controller : $this->load->library('table');

and the rest on view or what ever you like
$data = array(
array('Name', 'Color', 'Size'),
array('Fred', 'Blue', 'Small'),
array('Mary', 'Red', 'Large'),
array('John', 'Green', 'Medium')
);

echo $this->table->generate($data);

i just tested it with no errors

P.S. i dont know why you want this one $table = new \CodeIgniter\View\Table(); Tongue


RE: HTML Table Class new error! - videoproc - 07-16-2019

This is good in CI3! I try it in CI4 and there such code does not work! Help me please!


RE: HTML Table Class new error! - ciadmin - 07-16-2019

@mboutos This *is* the CodeIgniter 4 support subforum, hence the namespaced HTML Table usage ... https://codeigniter4.github.io/CodeIgniter4/outgoing/table.html

@videoproc Your usage looks right out of the user guide, and should work.

Need a bit more info for context ...
where in your controller is this happening? is it perhaps outside of any method?


RE: HTML Table Class new error! - InsiteFX - 07-16-2019

I just tried it in the Home Controller index method and it worked fine on my system.

Something else must be wrong on your end.

I' m using the latest developers version of CI 4.

Output:

Code:
Name    Color    Size
Fred    Blue    Small
Mary    Red    Large
John    Green    Medium



RE: HTML Table Class new error! - InsiteFX - 07-16-2019

Make sure you are running php 7.2+ it is required.


RE: HTML Table Class new error! - videoproc - 07-16-2019

Use php 7.3
My code:
PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Cron extends BaseController
{
    protected function 
nh_1min($params)
    {
        
$table = new \CodeIgniter\View\Table();
        
$data = array(
                array(
'Name''Color''Size'),
                array(
'Fred''Blue''Small'),
                array(
'Mary''Red''Large'),
                array(
'John''Green''Medium')
        );
        echo 
$table->generate($data);
    }
    
    public function 
_remap($method,...$params)
    {
 
       $nh_method 'nh_'.$method;
     
   if(method_exists($this$nh_method))
            return 
$this->$nh_method($params);
    }


Errors log:
Code:
<?php defined('SYSTEMPATH') || exit('No direct script access allowed'); ?>

CRITICAL - 17.07.2019 09:17:23 --> Class 'CodeIgniter\View\Table' not found
#0 C:\_OpenServer\OSPanel\domains\xxx.ru\app\Controllers\Cron.php(59): App\Controllers\Cron->nh_1min(Array)
#1 C:\_OpenServer\OSPanel\domains\xxx.ru\system\CodeIgniter.php(829): App\Controllers\Cron->_remap('1min')
#2 C:\_OpenServer\OSPanel\domains\xxx.ru\system\CodeIgniter.php(330): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Cron))
#3 C:\_OpenServer\OSPanel\domains\xxx.ru\system\CodeIgniter.php(240): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#4 C:\_OpenServer\OSPanel\domains\xxx.ru\public\index.php(45): CodeIgniter\CodeIgniter->run()
#5 {main}



RE: HTML Table Class new error! - videoproc - 07-17-2019

Updated CI to the latest version! It was beta 4.2. It all worked! I apologize for your concern!


RE: HTML Table Class new error! - InsiteFX - 07-17-2019

No problem, that's what we are here for.