-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
96 lines (71 loc) · 2.63 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
// VANILLA PHP
require_once 'Fmapi.php';
// You only need to do this once in your script.
$db = new Fmapi();
$db->user('fm_data_api_username')
->pass('secure_password')
->host('fm_server_dns_or_ip_address')
->db('my_layout_name')
->cache_path('./cache_dir/');
// get and cache a list of users for 4 hours
$users = $db->get('users')
->cache(4)
->result();
// array of objects or FALSE
// get a fresh copy of this user, and cache then cache valid result for 24 hours
$user = $db
->bust(TRUE)
->cache(24)
->where('username', 'sheldon')
->get('users')
->row();
// single object or FALSE
// Display a users avatar from a container field.
$avatar = $db->container($user->avatar_container);
if(!empty($avatar)) {
// render display
if(strpos($user->avatar_container, '.jpeg') !== FALSE) header('Content-type: image/jpeg');
if(strpos($user->avatar_container, '.jpg') !== FALSE) header('Content-type: image/jpeg');
if(strpos($user->avatar_container, '.png') !== FALSE) header('Content-type: image/png');
if(strpos($user->avatar_container, '.gif') !== FALSE) header('Content-type: image/gif');
echo $avatar;
die;
// display inline
echo '<imgh src="data:image/jpeg;base64,'. base64_encode($avatar) .'" alt="'. $user->first_name .'" />';
}
// Code Igniter 3
// Copy Fmapi.php to your application/libraries Directory
$this->load->library('fmapi');
$this->load->library('form_validation');
$this->fmapi
->user('fm_data_api_username')
->pass('secure_password')
->host('fm_server_dns_or_ip_address')
->db('my_layout_name')
->cache_path('./cache_dir/');
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Secure Password', 'trim|required|matches[confirm_password]|min_length[8]');
if($this->form_validation->run()) {
$this->fmapi->insert('users', [
'username' => $this->input->post('username'),
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'email' => $this->input->post('email'),
'password' => sha1($this->input->post('password')),
]);
}
// unchained query
$this->fmapi->reset();
$this->fmapi->cache(4);
if(!empty($username)) {
$this->fmapi->where('username', $username);
}
if(!empty($email)) {
$this->fmapi->where('email', $email);
}
$this->fmapi->get('users');
$users = $this->fmapi->result();