Welcome Guest, Not a member yet? Register   Sign In
HTML Table Class new error!
#1

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?
Reply
#2

(This post was last modified: 07-16-2019, 05:37 AM by mboufos. Edit Reason: forgot something )

check here
https://www.codeigniter.com/user_guide/l...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
Reply
#3

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

@mboutos This *is* the CodeIgniter 4 support subforum, hence the namespaced HTML Table usage ... https://codeigniter4.github.io/CodeIgnit...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?
Reply
#5

(This post was last modified: 07-16-2019, 08:33 AM by InsiteFX.)

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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

Make sure you are running php 7.2+ it is required.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(This post was last modified: 07-16-2019, 11:22 PM by videoproc.)

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}
Reply
#8

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

No problem, that's what we are here for.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB