Welcome Guest, Not a member yet? Register   Sign In
table->set_heading not doing anything
#1

I'm trying to use the table library and it looks very promising, however, I cant seem to modify the template. It looks simple enough. Too simple actually. I can't see anything to troubleshoot. It's just one line of code:

Code:
$this->table->set_template(array('table_open' => '<table class="table table-hover table-condensed">'));
$this->table->set_heading('id', 'Phone', 'Username', 'First', 'Last', 'Email', 'Created');
if(isset($users))
 foreach($users as $user)
    $this->table->add_row($user->id, $user->phone, $user->username, $user->first_name, $user->last_name, $user->email, $user->register_date);
echo $this->table->generate();
The above code works fine without the set_template call and adding the call makes no difference. I've also tried using set_template to change other elements and none of them do anything. Any ideas what I might be doing wrong?
Reply
#2

(12-12-2015, 09:55 PM)DSMatichuk Wrote: I'm trying to use the table library and it looks very promising, however, I cant seem to modify the template. It looks simple enough. Too simple actually. I can't see anything to troubleshoot. It's just one line of code:

Code:
$this->table->set_template(array('table_open' => '<table class="table table-hover table-condensed">'));
$this->table->set_heading('id', 'Phone', 'Username', 'First', 'Last', 'Email', 'Created');
if(isset($users))
 foreach($users as $user)
    $this->table->add_row($user->id, $user->phone, $user->username, $user->first_name, $user->last_name, $user->email, $user->register_date);
echo $this->table->generate();
The above code works fine without the set_template call and adding the call makes no difference. I've also tried using set_template to change other elements and none of them do anything. Any ideas what I might be doing wrong?


You should be setting the template like this:

PHP Code:
$template = array(
 
       'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">'
);

$this->table->set_template($template); 
What did you Try? What did you Get? What did you Expect?

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

Does anyone else have a suggestion? I am setting the $template correctly as far as I can tell and it is not making a difference. How do I troubleshoot this?
Reply
#4

Can I get some help with this?
Reply
#5

Which CI version are you using?
What do you mean exactly by "makes no difference"?
Reply
#6

(12-17-2015, 03:52 AM)Narf Wrote: Which CI version are you using?
What do you mean exactly by "makes no difference"?

I downloaded the latest version from the website just a few days ago  but it is possible that I am using the version I got from the online course I am taking. I do not know how to verify the version I am using. 

I am quite new to PHP so I am willing to be schooled on this but every course I have taken has told me that what I posted and what was suggested to me are identical, there is no difference.  

What I wrote in my question: 

$this->table->set_template(array('a' => 'b'));

Is identical to the recommendation I received: 

$template = array('a' => 'b');
$this->table->set_template($template); 

If there is a difference between those two then please educate me.

David
Reply
#7

There's no difference between these two pieces of code, but that's not what I asked ... How do you determine that the set_template() call does nothing? Do you just look at visual changes in the page or its actual output?

You can var_dump(CI_VERSION); to see which one you're using.
Reply
#8

CI v=3.0.1

I inspect the source. I have code to generate two identical tables. The first one is using the template and the second one is done manually. No matter what changes I make it to the first one, the first table does not change. When I view the page source it still shows the same attributes as if I had not set/changed them.
Reply
#9

Well, there are no changes to the Table library since version 3.0.1 and I can't reproduce your problem, so the only conclusion I can make is that you're somehow not using it properly.

If you show the complete code, surely somebody could spot the mistake.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB