Welcome Guest, Not a member yet? Register   Sign In
Library/Helpers and generating a table with only specific columns
#1

[eluser]stevek42[/eluser]
Hello,

I've been using CI for about 2 days or so and have been having a blast playing with its capabilities. I've built a basic system using FAL and multiple layouts that can display 'blocks' inside of pages. Doing so has raised two questions:

1. I've been using MVC for everything where an actual page is warranted like a Profile page or Home page. However, when I'm building a simple block that will be displayed within one or more pages, I've been using something like MLVH...I have some library functions that will call model functions in a generic way (to make the library functions re-usable). A helper calls the library functions and does something specific (like turning results into a table). And a view calls the helper. Is this the 'wrong' way to code views within views? I only do it this way because I don't want the controller generating a page, since the results are only meant to display in a view within a view. Should I be using controllers with private functions instead so I don't incur library overhead?

2. Is there a way to use table->generate() but only have it display certain columns? I am passing in a query resultset, and while I need all the results to build URLs and such, I only want the generated table to show one column. Will I have to extend the Table class to make something like this? It seems redundant to re-form the array and then generate a table.

Thanks, this product and community are extraordinary!
#2

[eluser]err403_love[/eluser]
For #2:

Code:
// In "view_file.php"

$this->table->set_heading('Heading Text');

foreach($query->result() AS $row)
{
    $this->table->add_row(
        anchor('link/path/'.$row->link_field.'/', $row->link_title)
    );
}
    echo $this->table->generate();

Where "link_field" and "link_title" are the fields you need to pull from the database. You didn't specify what fields went where, but you said you need those other fields to build the links, so I gave it an educated guess. Smile

This code is assuming you've made the query in your model/controller like so:
Code:
$data['query'] = $this->db->query("SELECT blah FROM blah ....");
$this->load->view('view_file',$data);

You'd need the URL helper, or to just write out the link code by hand.




Theme © iAndrew 2016 - Forum software by © MyBB