Welcome Guest, Not a member yet? Register   Sign In
Codeigniter newbie, help needed with views
#1

[eluser]Unknown[/eluser]
Okay, I need some serious help in laying out my pages!

If I were following Derek's tutorial on building a blog, how would I write that so that, instead of all the comments being on one page, each comment would be posted along with it's parent message? Also, since this kind of ties in, how would I go about designing a front page that has, say, a blog section, a link section, and a product section, all of which are dynamically generated?
#2

[eluser]Pascal Kriete[/eluser]
Hey dsullivan,

The first part is quite simple. It's essentially the same code as the comments function, but you'll add a query to get the entry.
Code:
function comments($id)
{
    $data['title'] = 'My Comment Title';
    $data['heading'] = 'My Comment Heading';
    
    // Get the blog entry *ADDED*
    $this->db->where('id', $id);
    $query = $this->db->get('comments');
    $data['entry'] = $query->row();            // No point in looping, we'll get the result here.
    
    // Get the comments
    $this->db->where('entry_id', $id);
    $data['query'] = $this->db->get('comments');
}
You'll also notice that I changed the code from using $this->uri->segment(3), to a function parameter. The segments that aren't used to work out the folder/controller/function are passed in as parameters. These two methods can be used interchangeably, but I find this way creates less work when working with folders (or one of the community module libraries), where the segment number may change.

Ideally you would do a database join to reduce it to one db call, but I don't know how much sql knowledge you have so this will work for now. Check out the database documentation for more info.


Your idea for the front page sounds pretty straight forward. You probably want to move your database stuff into models so you don't have to repeat it for different pages (that's what models are for Smile ). And then load and call the model function from your frontpage. It can be advantageous to split up the views into smaller chunks. You can have as many as you want, and load them in any imaginable way (including nesting them - data is passed along automagically).

Remember, the user guide for this framework is some of the best documentation ever written. Read it, then read it again, and you'll be up to speed in no time.

Welcome to CodeIgniter.




Theme © iAndrew 2016 - Forum software by © MyBB