Jump to content

Check if page exsists finds deleted pages


eutervogel
 Share

Recommended Posts

Hi, I got a little problem and I hope you could help me:
What I'm doing is this :

$page_exsists = $pages->get("title=$searchtitle");

The problem is, it finds pages that have exsited. I trashed them and emtied trash, but they still seem to be somewhere?!

So if I do $page_exsists->id; 

I get an id back?!

I hope you could understand my bad english „smile“-Emoticon 
Thanks for your help.

Link to comment
Share on other sites

A little bit more detail:

when I do this:

$page_exsists->url;

I get this:

/repeaters/for-field-152/for-page-0/

 So it seems, that the repeater fields are not deleted when the page is deleted.
 

If I search in my database for one of the ids I get back this is the result:
 

SELECT * 
FROM `MYDB`.`pages` 
WHERE (

CONVERT( `id` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `parent_id` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `templates_id` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `name` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `status` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `modified` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `modified_users_id` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `created` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `created_users_id` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `published` 
USING utf8 ) LIKE '%1157%'
OR CONVERT( `sort` 
USING utf8 ) LIKE '%1157%'

)
LIMIT 0 , 30
 

Link to comment
Share on other sites

Hi, the get selector give me troubles before too.

The best way to use it is with an ID as selector value:

$pages->get(1234);

Reading the doc's I found this:

Note that $pages->get("..."); is not subject to this behavior (or access control) and "include=all" is assumed.

Repeater's are actually pages that exists under the Admin menu.

So a get filtered by title will return this pages too.

If you need only one page use a findOne or a find with more filter's parameter's.

Hope that this help's you.

  • Like 2
Link to comment
Share on other sites

@eutervogel: $pages->get() always returns the first page, if any or multiple are found. But, unlike the $pages->find() method, it assumes that you, when using ->get(), you definetly want get this page and it has disabled access checking and uses include=all.

To understand what include=all and no access checking means, please try the following code to compare:

$page_exsists = $pages->find("title=$searchtitle")->first();

This will give you only pages that are not hidden and not locked and that are also be accessible, (no admin (sub)pages like repeater items).

But both, ->get() and find()->first(), will give you back a page object that has an ID! (find gives back a PageArray, = multiple page objects).

And in cases where no matching page can be found, it contains a NullPage. NullPages ever have an ID of 0 (zero).

So, if you want store a boolean, you can do it like this

$page_exsists = $pages->find("title=$searchtitle")->first()->id > 0;

But you also can check for NullPage, or if count() of the pageArray is greater than 0, or if it matches exactly 1, or if it contains multiple pages.

Hope this helps a bit. :)

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...