Flash Builder 4 can consume PHP classes directly as data services via the Zend AMF class. How would I integrate such PHP classes into a CI app? For example, what if I need to authenticate my PHP data service class from a current CI user that is logged into the app?
Basically, I need to embed a Flash Builder app into some pages of my CI app, and issue calls to these PHP classes.
Code:
<?php
class EmployeeService {
var $username = "dbuser";
var $password = "dbpassword";
var $server = "127.0.0.1";
var $port = "3306";
var $databasename = "testdrive_db";
var $tablename = "employees";
var $connection;
public function __construct() {
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename,
$this->port
);
$this->throwExceptionOnError($this->connection);
}
public function getEmployees() {
$stmt = mysqli_prepare($this->connection,
"SELECT
employees.id,
employees.firstname,
employees.lastname,
employees.title,
employees.departmentid,
employees.officephone,
employees.cellphone,
employees.email,
employees.street,
employees.city,
employees.state,
employees.zipcode,
employees.office,
employees.photofile
FROM employees");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->firstname,
$row->lastname, $row->title, $row->departmentid,
$row->officephone, $row->cellphone, $row->email,
$row->street, $row->city, $row->state,
$row->zipcode, $row->office, $row->photofile);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->firstname,
$row->lastname, $row->title, $row->departmentid,
$row->officephone, $row->cellphone, $row->email,
$row->street, $row->city, $row->state,
$row->zipcode, $row->office, $row->photofile);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
public function getEmployeesByID($itemID) {
$stmt = mysqli_prepare($this->connection,
"SELECT
employees.title,
employees.street,
employees.id,
employees.firstname,
employees.lastname,
employees.cellphone,
employees.departmentid,
employees.zipcode,
employees.office,
employees.email,
employees.state,
employees.officephone,
employees.photofile,
employees.city
FROM employees where employees.id=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->title, $row->street, $row->id,
$row->firstname, $row->lastname, $row->cellphone,
$row->departmentid, $row->zipcode, $row->office,
$row->email, $row->state, $row->officephone ,
$row->photofile, $row->city);
if (mysqli_stmt_fetch($stmt)) {
return $row;
} else {
return null;
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
}
public function createEmployee($item) {
$stmt = mysqli_prepare($this->connection,
"INSERT INTO employees (
firstname,lastname,title,departmentid,officephone,cellphone,
email,street,city,state,zipcode,office,photofile)
VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?)");
$this->throwExceptionOnError();
mysqli_bind_param($stmt, 'sssisssssssss', $item->firstname, $item->lastname,
$item->title, $item->departmentid, $item->officephone, $item->cellphone,
$item->email, $item->street, $item->city, $item->state,
$item->zipcode, $item->office, $item->photofile
);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}