Page class method differences

edited September 2015 in Share
I'm using a regular CI controller to enhance data in a CMS page (the index), using Fuel v1.3. The CMS page uses a custom layout.

While the page is published it works, and when unpublished, and logged in, the page returns but with the inline edit message "The page is not published", which is as expected. However, when not logged in, the unpublished page returns an empty blank page. I'd prefer it to 404. So I looked up the Page class methods, and used get() to fetch the page object. It always returns the is_published value as 1, even when the page is conspicuously unpublished. Using another method, find(), fails to even find an unpublished page (but returns true if it is published). That's what I need, so in the __construct() I add:

$page = $this->fuel->pages->find(uri_segment(1)); if(!is_array($page) || $page['published'] == 'no') { show_404(); }

Why is there a difference between pages->get() and pages->find() in this circumstance, regarding the published status?

Incidentally, the documentation suggests find() returns an object, but I get an array()

Comments

  • edited 8:52AM
    The documentation is incorrect and "find" returns an array."get" will return an object. If you are wanting to ensure that the page is being pulled from the cms instead of a view, add the following initialization parameter.
    $this->fuel->pages->get('test', array('render_mode' => 'cms'));
  • edited June 2016
    I found the need for this issue again recently. I suppose what I really wanted was an efficient way of finding if a page has content, and if it is published. I wrote my own helper to do this, so it returns false if nothing matches the uri location, or the value of 'published' otherwise.
Sign In or Register to comment.