Nothing documented outside of the code. I usually start by guessing which module has the functions I want and grep for “public function”. Most are named with get in the name:
<?php
include '/etc/freepbx.conf';
$FreePBX = FreePBX::Create();
$devices=$FreePBX->Core->getAllDevicesByType();
$device=$FreePBX->Core->getDevice("6008");
$user=$FreePBX->Core->getUser("6008");
With that simple PHP script you’re not bringing in your authenticated session. Add at the top before you include /etc/freepbx.conf:
// this is from config.php
if (!isset($_SESSION)) {
//start a session if we need one
$ss = @session_start();
if(!$ss){
session_regenerate_id(true); // replace the Session ID
session_start();
}
}
Or bypass auth altogether with:
$bootstrap_settings['freepbx_auth'] = false;
before requiring /etc/freepbx.conf. But of course, disclaimer: bypass security at your own peril.
I’m not a PHP dev. I copy/edit/modify. Thanks for the tip.
In this case, I am already in a loop and know the exact extension I want. Are you saying I should pull this once and then jsut go down the object then?
maybe:
We all start with examples and php makes bad habits really easy. I will always do my best to give good code examples. Note my old code may also have some of these bad habits. We all learn and grow hopefully.
If you can afford the data structure memory wise it is always useful to put it in memory. Without a full scope of your end goal I couldn’t say. Premature optimization is the devil so ideally make it work first then clean up.
If you want to hold a smaller data structure you can use something like array_walk to reduce the size of the data structure only keeping the keys you want