Jump to content
cb2004

$pages->find in config.php

Recommended Posts

I need to get an array of IDs in the config.php files to workaround something. Is there any way to do this, I have tried wire('pages') but dont seem to be having much joy.

Share this post


Link to post
Share on other sites

You'll need to do it with raw SQL. Something like this:

$pdo = new \PDO("mysql:host=$config->dbHost;dbname=$config->dbName", $config->dbUser, $config->dbPass);
$stmt = $pdo->query('SELECT `id` FROM pages WHERE templates_id = "29"');
$rows = $stmt->fetchAll(\PDO::FETCH_NUM);

 

  • Like 3

Share this post


Link to post
Share on other sites
6 hours ago, adrian said:

You'll need to do it with raw SQL. Something like this:


$pdo = new \PDO("mysql:host=$config->dbHost;dbname=$config->dbName", $config->dbUser, $config->dbPass);
$stmt = $pdo->query('SELECT `id` FROM pages WHERE templates_id = "29"');
$rows = $stmt->fetchAll(\PDO::FETCH_NUM);

 

Thanks so much for your reply Adrian. In the end I went with a solution in ready.php:

$members = wire('pages')->get(1302)->children;
$subMembers = array();
foreach($members as $m) $subMembers[] = $m->id;

And in config.php:

$config->usersPageIDs = array_merge($config->usersPageIDs, $subMembers);

Seems to be working ok, but what route would be best/fastest?

Share this post


Link to post
Share on other sites

@cb2004 - if that works, great - I didn't think it would work to set something in ready.php and use it in config.php

PS - you can simplify the $subMembers bit to:

$subMembers = wire('pages')->get(1302)->children->each('id');

or even better because it won't load the pages, just their IDs:

$subMembers = wire('pages')->findIDs('parent=1302');

 

  • Like 3

Share this post


Link to post
Share on other sites

Hahaha, read the post to the end before answering 😄 

d9gI3yq.png

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...