Codeigniter by Beni - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

The keen-eyed amongst you will also notice the highlighted lines, we've defined the start and end points for CodeIgniter to pay attention to. The first we've named bm1_start and the second we've named bm1_stop. We can call them anything we like, but that's what I've decided to call them.

We then perform the batch_ insert operation, as shown in the following code snippet: $this->benchmark->mark('bm2_start');

$data = array(

array('firstname' => 'George',

'lastname' => 'Foster'),

array('firstname' => 'Jackie',

'lastname' => 'Foster'),

array('firstname' => 'Antony',

'lastname' => 'Welsh'),

array('firstname' => 'Rowena',

'lastname' => 'Welsh'),

array('firstname' => 'Peter',

'lastname' => 'Foster'),

array('firstname' => 'Jenny',

'lastname' => 'Foster'),

array('firstname' => 'Oliver',

'lastname' => 'Welsh'),

array('firstname' => 'Harrison',

'lastname' => 'Foster'),

array('firstname' => 'Felicity',

'lastname' => 'Foster')

);

$result = $this->bench_model->add_to_db($data);

$this->benchmark->mark('bm2_end');

281

SEO, Caching, and Logging

We're defining a multidimensional array with the details of people we want to add to the database and sending it to the insert_batch() function of bench_model; now the keen eyed among you will again notice the highlighted lines. These are the bm2 start and end points. If the batch_insert() operation returns TRUE (it is inserted into the database correctly), we then call the get_people() model function again, which will return all the records from the database:

if ($result) {

// Who's in the database now?

$this->benchmark->mark('bm3_start');

foreach ($this->bench_model->get_people()->result() as $row) {

echo $row->firstname . ' ' . $row->lastname . '<br />';

}

$this->benchmark->mark('bm3_end');

} else {

echo 'Cannot write to database.';

}

Again, here we define (as highlighted in the previous code) the bm3 start and end points.

That completes our database operations and we move over to reporting of the benchmarks.

We ask CodeIgniter to tell us the execution time between points:

echo '<br /> ---- BENCHMARK POINT STATS ---- <br />';

echo 'BM1 (S) to BM1 (E): ' . $this->benchmark->elapsed_time('bm1_

start','bm1_end') . '<br />';

echo 'BM2 (S) to BM2 (E): ' . $this->benchmark->elapsed_time('bm2_

start','bm2_end') . '<br />';

echo 'BM3 (S) to BM3 (E): ' . $this->benchmark->elapsed_time('bm3_

start','bm3_end') . '<br />';

For each bm1, bm2, and bm3, we want to know the time between the points specified using the $this->benchmark->elapsed_time() function. This function takes two arguments: a start point and an end point. For this recipe, we have asked CodeIgniter to report the time elapsed between each bm# point (where # is the number 1, 2, or 3), but if we wish to we can write this:

echo 'BM1 (S) to BM2 (E): ' . $this->benchmark-

>elapsed_time('bm1_start','bm2_end') . '<br />'

The previous code will report the elapsed time between bm1_start and bm2_end (or from the beginning of the first get_people() query to the end of the batch_insert() query).

Think of each $this->benchmark->mark('bm2_end'); as a checkpoint, and you can use $this->benchmark->elapsed_time('checkpoint_1','checkpoint_2') to return the time elapsed between them.

282

Index

Symbols

$data_to_write variable 116

$db[‘default’][‘cachedir’] option 11

$cap array 262

$db[‘default’][‘cache_on’] option 10

$config 164

$db[‘default’][‘char_set’] option 11

$config[‘cookie_domain’] = \ 126

$db[‘default’][‘database’],

$config[‘cookie_path’] = \ 127

config item 17, 234

$config[‘cookie_prefix’] = \ 126

$db[‘default’][‘database’] option 10, 100

$config[‘cookie_secure’] = FALSE; 127

$db[‘default’][‘dbcollat’] option 11

$config[‘csrf_cookie_name’],

$db[‘default’][‘db_debug’] option 10

config item 106, 171

$db[‘default’][‘dbdriver’] option 10

$config[‘csrf_expire’], config item 106, 171

$db[‘default’][‘dbprefix’] option 10

$config[‘csrf_protection’],

$db[‘default’][‘hostname’],

config item 106, 171

config item 17, 234

$config[‘csrf_token_name’],

$db[‘default’][‘hostname’] option 10, 100

config item 106, 171

$db[‘default’][‘password’],

$config[global_xrsf_filtering’],

config item 17, 234

config item 106

$db[‘default’][‘password’] option 10, 100

$config[‘sess_cookie_name’],

$db[‘default’][‘pconnect’] option 10

config item 16, 233

$db[‘default’][‘port’] option 11

$config[‘sess_encrypt_cookie’],

$db[‘default’][‘username’],

config item 16, 233

config item 17, 234

$config[‘sess_expiration’],

$db[‘default’][‘username’] option 10, 100

config item 16, 233

$delimeter 167, 168

$ config[‘sess_expire_on_close’],

$dob array 205

config item 16, 233

$end_of_month variable 189

$config[‘sess_match_ip’],

$filename variable 216

config item 16, 234

$future_descriptions array 209

$config[‘sess_match_useragent’],

$hash 39, 50

config item 16, 234

$hook array 218

$config[‘sess_table_name’],

$month_as_written array 189

config item 16, 233

$newline 167, 168

$config[‘sess_use_database’],

$path array 116

config item 16, 233

$prefs array 200

$data array 39, 86, 98, 190, 216, 262

$query 164, 166, 168

$start_date variable 189

BM1 (S) 280

$start_of_month variable 189

bulk e-mails

$this->benchmark->elapsed_time()

sending, with CodeIgniter Email 76-79

function 282

$this->Cart_model->get_all_products()

C

function 59

$this->db->insert() 140

cache_override 217

$this->db->insert_batch() 140

caching 268-272

$this->table->generate() function 86, 90

Cactuslab

$time_in variable 209

ImageMagick, installing on MAC 241, 242

$tpl variable 200

Calendar Library

.htaccess file

appointment manager, building with 190-200

used, for removing index php from

callbacks

address bar 12

validating 122, 123

/path/to/codeigniter/application/

CAPTCHA

controllers/makepdf.php file 214

form, submitting with 257-263

/path/to/codeigniter/application/models/

cart

makepdf_model.php file 214

basic cart, ammending 54-58

/path/to/codeigniter/application/views/

items, adding 59

makepdf/view_all_users.php file 214

items, removing 59

items, subtracting 59

A

items, updating 59

saving, to database 63-67

Active Record

categories

create (insert) 140

products, adding by 59

delete 148

products, searching by 59-62

read (select) 144

categories table 53

update 146

censor_model function 97

address bar

clear_now() function 220

index.php removing, .htaccess file used 12

clear_sessions.php file 220

allowed_types setting 119

CodeIgniter

alpha 105

about 5

alpha_dash 105

caching, using 268-272

alpha_numeric 105

CAPTCHA, form submitting with 257-264

APC (Alternative PHP Caching) 272

cart class 51

app_cal controller 186

configuration, options 6, 7

application

configuring, for databases 134, 135

benchmarking 277-282

downloading 5, 6

appointment manager

files, uploading with 118-121

building, with Calendar Library 190-200

form elements, sticky 110, 111

attachments

form, submitting with CodeIgniter

sending, with CodeIgniter Email 74-76

CAPTCHA 257-263

fuzzy dates 205, 209, 210

B

hooks, creating 217-219

HTTPS, using with 178-180

batch_insert() operation 281, 282

284

images, cropping 249-252

current version

images, rotating 247

moving to, current() used 161

images, uploading with 242-244

logging errors 272-276

D

logging errors, style 277

managing, on different environments 7, 8

data

passwords, generating with 31-41

deleting, from database 148-150

passwords, resetting with 43-50

escaping 173-177

SEO-friendly URLs, using 265-268

inserting, in database 140-143

thumbnails, creating 244, 246

managing 100

watermarks, adding with image

selecting, from database 144-146

overlays 255-257

sending, to multiple views 100-103

watermarks, adding with text 252-254

updating, in dtabase 146, 148

CodeIgniter Calendar helper

database

building, with database results 183-190

accessing, through library 227-230

CodeIgniter database migrations

cart, saving 63-67

using 157-160

CodeIgniter, configuring for 134, 135

CodeIgniter Email

dead sessions, clearing 219-221

attachments, sending with 74-76

HTML table, using with 86-90

bulk e-mails, sending with 76-80

multiple databases, connecting to 135-139

HTML e-mails, sending with 72-74

database query

used, for sending e-mails 70, 71

last database query, finding 156, 157

CodeIgniter Sparks

database result

using 212, 213

CodeIgniter Calendar helper,

configuration settings

building with 183, 184-190

amending, to run sessions in database 51-53

CSV, generating from 165

creating 231, 232

looping through 150, 151

controllers

XML, generating from 163, 164

extending 222, 223

database schema 17, 18

cookie

database settings

acceptance from user, confirming 126-132

managing, on different environments 8-11

count_all_results()

DataTable

returned results number, counting 153, 154

HTML table, using with 81-90

create_batch() public function 143

day_type 187

create() function 143, 193, 200, 201

dbutil function 225

Create, Read, Update, and Delete (CRUD)

dead sessions

operations 134

clearing, from database 220, 221

cross-site request forgery

decimal 105

preventing 171-173

delete() function 195

CSRF. See cross-site request forgery

delete_user(), public function 30

CSV

display_override 217

creating, from database result 165, 166

dompdf function 216

csv_from_result() function 168

DOMPDF Spark

current() function 161

used, for creating PDFs 213-216

do_upload() function 256

285

E

G

e-mails

get_all() function 94

bulk e-mails, sending with

get_main_article() function 102

CodeIgniter Email 76-80

greater_than rule 104

HTML e-mails, sending with

CodeIgniter Email 72, 73

H

sending, with CodeIgniter Email 70, 71

encrypt_name setting 120

hash

errors

comparing 42

displaying, next to form items 112, 113

generating 41

escape_like_str() 177

generating, with $config[‘encryption_key’]

escape_str() 177

value 42

escaping data 173-177

generating, without $config[‘encryption_key’]

escaping user input

value 42

about 169

helper

globally 170

creating, to work with persons date

individually 170

of birth 202-205

exact_length rule 104

Hooks

cache_override 217

F

creating, in CodeIgniter 216-219

display_override 217

file_name setting 119

post_controller 217

files

post_controller_constructor 217

reading, from file system 113-115

post_system 217

uploading, with FTP 223-226

pre_controller 217

uploading, with CodeIgniter 118-122

pre_system 217

writing, to file system 116

HTML e-mails

file system

sending, CodeIgniter Email used 72, 73

files, reading from 113-115

HTML table

files, writing to 116

using, with database 86-90

force_download() 166

using, with Data table 83-90

foreach() loop 151

HTTPS