Welcome Guest, Not a member yet? Register   Sign In
Cannot figure out Pagination + custom design
#1

[eluser]Zero-10[/eluser]
I've been really good at figuring stuff out on my own but the Pagination system is insanely confusing for some reason. I created my own gallery where images can be uploaded and stored via database and the data is displayed fine with the pagination. However, I cannot figure out how to display the results with pagination. My main goal is to get a comment system for articles, and the gallery was used as a way to figure things out and won't be code used in the future. I'm just stating that I managed to use the pagination (table) correctly.

Files:
Controller/entertainment/article
Models/articles/entertainment
Views/entertainment/index | Views/entertainment/comments

Example of URL:
http://www.fakeurl.com/entertainment/4/title-of-article
4 = articleid
title-of-lesson = isn't mandatory but is good for SEO

Article Controller (comments function)
Code:
//removed a bunch of code that is not important for this question like phpbb stuff
            // retrieve article
            $articleid = $this->uri->segment(4, 6);
            $fulltitle = $data['l_title'];
            $this->load->model('articles/get_article','',TRUE);
            $data['article'] = $this->get_article->get_article_by_id_ent($articleid);

            // retrieve pageviews
            $this->load->model('siteviews','',TRUE);
            $data['pageviews'] = $this->siteviews->get_entertainmentviews($articleid);

            // get breadcrumb id
            $id = $this->breadcrumb->get_categoryid_by_article($data['article']);
            $data['crumb'] = $this->_breadcrumb($id);

            $this->db->set('name', $name);
            $this->db->insert('mytable');

            // get last 24 articles
            $data['ladded'] = $this->get_article->get_latest_added_entertainment();

            // get character database
            $this->load->model('character_database','',TRUE);
            $data['ch_characters'] = $this->character_database->get_characters($articleid);

            // friendship system
            $this->load->model('friendship','',TRUE);
            $data['friendpage'] = $this->friendship->get_advertisement('id', $adcategory);
            $data['friendcount'] = $this->friendship->get_viewcountads();
                $data['friendpage2'] = $this->friendship->get_advertisement2('id', $adcategory);
                $data['friendcount2'] = $this->friendship->get_viewcountads2();

            // Retrieve comments
            $this->load->model('articles/comments','',TRUE);

            $this->db->where('database_entertainment', $this->uri->segment(3));
            $data['fullurl'] = $this->get_article->get_article_by_id_ent('full_url', $articleid);

            // load pagination class
            $this->load->library('pagination');
            $config['base_url'] = base_url().'entertainment/articles/information/'.$articleid;
            $config['total_rows'] = $this->db->count_all('database_articles_comments');
            $config['per_page'] = '1';
            $config['full_tag_open'] = '<p>';
            $config['full_tag_close'] = '</p>';

            $this->pagination->initialize($config);
            $data['cm_query'] = $this->comments->get_comments_ent
            $this->load->library('table');
            $this->table->set_heading('cm_articles_id', 'cm_articles_author', 'cm_articles_date', 'cm_articles_body');

            $this->load->view('header', $data, $aid);
            $this->load->view('entertainment/viewarticle', $data, $bodytext);

Models/articles/comments
Code:
&lt;?php

class Comments extends Model {

    function Comments() {
        parent::Model();
    }
            function get_comments_ent($articleid) {
            $this->db->select('*');
            $this->db->from ('database_entertainment_comments AS p');
            $this->db->join('phpbb_users AS b', 'p.cme_articles_author = b.user_id', 'left');
            $this->db->where('p.cme_articles_article =', $articleid);
            $this->db->order_by('p.cme_articles_date', 'desc');
            $this->db->limit($per_page);

            return $this->db->get();
    }
        function add_comment($data)
        {
            $this->db->insert('database_entertainment_comments', $data);
            return;
        }
}

?&gt;

View/entertainment/comments
-- No point in adding header and index files --
Code:
&lt;? if ($cm_query->num_rows() >0): ?&gt;
    &lt;? foreach($cm_query->result() as $row): ?&gt;
<div>//comment div and things like &lt;?=$row->username?&gt; says: has been removed for simplicity</div>
    &lt;?php endforeach; ?&gt;
&lt;? endif; ?&gt;
//more code deleted for simplicity including the num_rows else case.
&lt;?php echo $this->pagination->create_links(); ?&gt;

I have read like 15 different tutorials (they are all the same copypata), watched the nettuts video, and even went on youtube and other video sites for other screencasts but they don't go into how to customize it. Eventually I would love to have a "load more comments" with jquery but I'll be more than content with getting this done.

Thank you for your time!
#2

[eluser]Zero-10[/eluser]
Almost 3 days has gone by so I'm bumping this for interest. I haven't figured this one out yet Sad
#3

[eluser]boltsabre[/eluser]
Quote:and the data is displayed fine with the pagination. However, I cannot figure out how to display the results with pagination.
Not really sure what your problem is, you said the data is displayed fine with pagination, and then the very next sentance you say its not working, can you please reword this for us.

Quote:I’m just stating that I managed to use the pagination (table) correctly.
So is pagination working or not? Very confused....

Quote:Files:
Controller/entertainment/article
Models/articles/entertainment
Views/entertainment/index | Views/entertainment/comments

Example of URL:
http://www.fakeurl.com/entertainment/4/title-of-article
4 = articleid
title-of-lesson = isn’t mandatory but is good for SEO

So okay, if you want SEO urls (ie, segment 3 above), you'll have to write your own helper (and perhaps form validation class extension with a custom rule). In your helper, before entry of the title to the DB (you'll have to make an extra table field for this to store it in) you'll have to strip all non alpha/numeric/hyphan characters from your string, and then replace all spaces with hyphans. This can get complicated if you want to (consider a user enters this for a title: "this is my title ", your resulting seo friendly url will be "http://www.fakeurl.com/entertainment/4/this------is------my-title----/".

Anyway, again, im not really sure what the problem is, if you could re-clarify then perhaps you'll get some more answers! good luck, i'll check back later and see what you've posted.
#4

[eluser]InsiteFX[/eluser]
For one you did not say what version of CodeIgniter you are using!

But if your using CodeIgniter 2.0.+ then your Controller and Model are wrong!

CI 2.0.+
Controller extends CI_Controller
Model extends CI_Model

Constructor is:
Code:
public funtion __construct()
{
    parent::__construct();
}

InsiteFX
#5

[eluser]Zero-10[/eluser]
I'm using 1.7 without plans of upgrading since my personal project is already 95% complete.

The default pagination table displays data from the database but I don't want that ugly looking table. It looks like something used for testing purposes. I want to make something that involves a dozen divs with relative and absolute properties and a lot of CSS.

If I tell the pagination to get data from the database using the default table class then it will do it but I don't want to use it for the reasons mentioned above. I want to select certain columns and display what i want when i want it in the result tag (&lt;? foreach($cm_query->result() as $row): ?&gt;)

Thanks for your time and the responses so far!

EDIT: Don't worry about the SEO thing, that was the first thing I did with this project, I'm just saying that the last piece in the url isn't mandatory so you can still access it without it. I was saying that in the event that the url parameter needed to be increased or decreased by 1.




Theme © iAndrew 2016 - Forum software by © MyBB