joostvanveen / build-a-cms-with-codeigniter

Source code for the Tutsplus course 'Build a CMS with Codeigniter'
53 stars 55 forks source link

Issue with Ordering Pages #4

Closed mesaugat closed 10 years ago

mesaugat commented 11 years ago

There is a issue with the ordering of pages. If we put Homepage as a child of About or Contact and hit the save button 'homepage' will not show up after the save.

Similarly if we put homepage and contact as a child of about. Then again the homepage doesn't show up. Take a look at the screenshot below:

my awesome cms_2013-08-27_10-56-37 The above pages show the following order, homepage is missing. Is this a problem or I am not getting the concept behind ordering the pages?

my awesome cms_2013-08-27_10-56-23

joostvanveen commented 11 years ago

Actually, is that is a problem.

In your screenshot, I can also see the homepage, in the third line. I am not sure where the second screenshot is from. Probabaly the admin ordering page without markup.

Anyway, I tried to reproduce this, using the original source code, but it works fine in my case, see attached screenshots. I have made the homepage a child of contact and it shows up in both admin and frontend. There's probably something you are missing.

If the second screenshot is indeed form admin/page/order then there is probably something wrong with the data returned from page_m::get_nested() You may want to check this model method against the source code.

schermafbeelding 2013-08-27 om 10 36 05 schermafbeelding 2013-08-27 om 10 36 16 schermafbeelding 2013-08-27 om 10 36 27

mesaugat commented 11 years ago

Yes indeed, the second screenshot is from 'admin/page/order' and the homepage is missing but is not missing in the 'admin/page'. I am not able to solve this problem. Yes the data from get_nested() is wrong. I am trying to figure it out.

joostvanveen commented 11 years ago

You are bound to have an error in this bit of code:

            $array = array();
    foreach ($pages as $page) {
        if (! $page['parent_id']) {
            // This page has no parent
            $array[$page['id']] = $page;
        }
        else {
            // This is a child page
            $array[$page['parent_id']]['children'][] = $page;
        }
    }
    return $array;
mesaugat commented 11 years ago

I have gone through the code several times. The code is perfectly correct but I think their is a logical error somewhere. I also tried with the project files for "11-12-13-managing-pages" and it is disappearing in it too. It's making me mad now !

But, I cloned this repo and it is working fine. Are the project files any different from this ?

joostvanveen commented 11 years ago

They should be the same.

Lesson 11-12-13 This is where I added ordering, like $page->parent_id = 0, public function save_order ($pages), public function get_nested (), public function get_with_parent ($id = NULL, $single = FALSE), public function get_no_parents () Lesson 17: added $page->template Lesson 18-19: added public function get_archive_link() Lesson 22: added protected $_order_by = 'parent_id, order';

devsantoshm commented 6 years ago

hi the error is in the method get_nested, can you look my issue please?

devsantoshm commented 6 years ago

Hi Sir, you're awesome teaching in this course, but I have a problem in the file page_m.php with the method get_nested(), when i have my records in phpmyadmin of this manner

id title .... parent_id 1 homepage ... 0 5 contact ... 6 6 about ... 0

in the method get_nested(), just back array only with parent_id=0, but not the children:

Dump => array(2) { [1] => array(6) { ["id"] => string(1) "1" ["title"] => string(8) "Homepage" ["slug"] => string(1) "/" ["order"] => string(1) "1" ["body"] => string(241) "Multiple function calls can be made if you need several joins in one query. If you need a specific type of JOIN you can specify it via the third parameter of the function. Options are: left, right, outer, inner, left outer, and right outer." ["parent_id"] => string(1) "0" } [6] => array(6) { ["id"] => string(1) "6" ["title"] => string(5) "about" ["slug"] => string(5) "about" ["order"] => NULL ["body"] => string(46) "

esta página about

" ["parent_id"] => string(1) "0" } } but, If I change the order of my records in phpmyadmin

id title .... parent_id 1 homepage ... 0 5 contact ... 0 6 about ... 5

I get the children

Dump => array(2) { [1] => array(6) { ["id"] => string(1) "1" ["title"] => string(8) "Homepage" ["slug"] => string(1) "/" ["order"] => string(1) "1" ["body"] => string(241) "Multiple function calls can be made if you need several joins in one query. If you need a specific type of JOIN you can specify it via the third parameter of the function. Options are: left, right, outer, inner, left outer, and right outer." ["parent_id"] => string(1) "0" } [5] => array(7) { ["id"] => string(1) "5" ["title"] => string(7) "contact" ["slug"] => string(7) "contact" ["order"] => NULL ["body"] => string(36) "

nbuevo ontenido

" ["parent_id"] => string(1) "0" ["children"] => array(6) { ["id"] => string(1) "6" ["title"] => string(5) "about" ["slug"] => string(5) "about" ["order"] => NULL ["body"] => string(46) "

esta página about

" ["parent_id"] => string(1) "5" } } }

How can I resolve this problem?

Regards.

joostvanveen commented 6 years ago

@devsantoshm if that is the case then the records are not being ordered correctly by the SQL statement. They should be order by parent_id, position. This make sure all parent pages are first in the result set.

Line 75 does this:

$this->db->order_by($this->_order_by);

$this->_order_by is defined on line 5

devsantoshm commented 6 years ago

@joostvanveen ok thanks, but i have another problem with the plugin tinymce, when edit one registry, always add another paragraph p "< p >< /p >" of this manner

< p >< p >< p >< p >esta página about< /p >< /p >< /p >< /p >

when i click in button edit, add a new paragraph

< p >< p >< p >< p >< p >esta página about< /p >< /p >< /p >< /p >< /p >

how can i resolve this problem?

thanks.

devsantoshm commented 6 years ago

@joostvanveen ok thanks, but i have another problem with the plugin tinymce, when edit one registry, always add another paragraph p "< p >< /p >" of this manner

< p >< p >< p >< p >esta página about< /p >< /p >< /p >< /p >

when i click in button edit, add a new paragraph

< p >< p >< p >< p >< p >esta página about< /p >< /p >< /p >< /p >< /p >

how can i resolve this problem?

thanks.

joostvanveen commented 6 years ago

Sorry, can't help you there, @devsantoshm