Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:09:19+00:00 2026-06-05T13:09:19+00:00

OK, below is a get_members function in my controller that I pulled and manipulated

  • 0

OK, below is a get_members function in my controller that I pulled and manipulated from the interwebs… i can print out the information from $output in the controller, but I don’t want to do that… I cannot figure out how to get it to be part of my view so I can list info from it freely…

I know it has something to do with the $data array in the index function… can anyone assist?

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Phonedirectory extends CI_Controller {

function get_members($group=FALSE,$inclusive=FALSE) {
    // Active Directory server
    $ldap_host = "fps";

    // Active Directory DN
    $ldap_dn = "OU=Users,DC=xxx,DC=org";

    // User attributes we want to keep
    $keep = array(
        "samaccountname",
        "displayName",
        "telephonenumber"
    );

    // Connect to AD
    $ldap = ldap_connect($ldap_host) or die("Could not connect to LDAP");
    ldap_set_option ($ldap, LDAP_OPT_REFERRALS, 0);
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);

    ldap_bind($ldap, "CN=LDAP Reader,OU=Users - Special,DC=xxx,DC=org", "xxx") or die("Could not bind to LDAP");

     // Begin building query
     if($group) $query = "(&"; else $query = "";

     $query .= "(&(objectClass=user)(objectCategory=person))";

    // Filter by memberOf, if group is set
    if(is_array($group)) {
        // Looking for a members amongst multiple groups
            if($inclusive) {
                // Inclusive - get users that are in any of the groups
                // Add OR operator
                $query .= "(|";
            } else {
                // Exclusive - only get users that are in all of the groups
                // Add AND operator
                $query .= "(&";
            }

            // Append each group
            foreach($group as $g) $query .= "(memberOf=OU=$g,$ldap_dn)";

            $query .= ")";
    } elseif($group) {
        // Just looking for membership of one group
        $query .= "(memberOf=OU=$group,$ldap_dn)";
    }

    // Close query
    if($group) $query .= ")"; else $query .= "";

    // Uncomment to output queries onto page for debugging
    // print_r($query);

    // Search AD
    $results = ldap_search($ldap,$ldap_dn,$query);
    $entries = ldap_get_entries($ldap, $results);

    // Remove first entry (it's always blank)
    array_shift($entries);

    $output = array(); // Declare the output array

    $i = 0; // Counter
    // Build output array
    foreach($entries as $u) {
        foreach($keep as $x) {
            // Check for attribute
            if(isset($u[$x][0])) $attrval = $u[$x][0]; else $attrval = NULL;

            // Append attribute to output array
            $output[$i][$x] = $attrval;
        }
        $i++;
    }
    return $output;
}

public function index() {
  $data = array('title' => 'Phone Directory', 'main_content' => 'pages/phoneDirectory');    
  $this->load->view('template/main', $data);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:09:21+00:00Added an answer on June 5, 2026 at 1:09 pm

    Correct me if I’m wrong, but it sounds like you just want the output sent to the view?
    If that’s the case, then add this to the index function

    public function index() {
      $data = array('title' => 'Phone Directory', 'main_content' => 'pages/phoneDirectory'); 
      $data['members'] = $this->get_members();
      $this->load->view('template/main', $data);
    }
    

    or however you want to append that to your data array.
    Then in the view you can do:

    <?php echo print_r($members, TRUE); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an ide/site that I can use to analyse code below and get
From the demo below you can probably see what I am trying to do,
The function below, as its name suggests, registers/records the data from signup form into
The two programs below get n integers from file and calculates the sum of
I am using the script code below to get results from my database based
I created the below function to get FirstName and LastName and place them into
Below is a very simple bit of code that mimics a class structure in
The example below uses a function pointer to a member function of the class
I'm trying to use the SUM function to count rows from 3 tables, which
I am working on an AJAX system to submit a form, but I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.