37. // ------------------------------------------------------------
// User Login
// ------------------------------------------------------------
// If the credentials were correct, login and redirect to dashboard
// Otherwise, redirect to the login form with errors
38. // ------------------------------------------------------------
// User Login
// ------------------------------------------------------------
// If the credentials were correct, login and redirect to dashboard
if($this->auth->login($email, $password) === TRUE)
{
redirect('account/dashboard');
}
// Otherwise, redirect to the login form with errors
else
{
$this->session->set_userdata('errors', $this->auth->errors);
redirect('login');
}
42. // @TODO: Handle failed API requests better
// @NOTE: Passing by reference is necessary here
// @HACK: Fixed minor bug in query builder
// @SEE: http://tinyurl.com/2g9mqh
// @BLAME: Alex royally screwed this up
52. /**
* Hashes an array of settings for easy storage in a database
*
* @param array $data
* @return string
*/
public static function hash_settings($data)
{
return base64_encode(serialize($data));
}
60. // At this point we need to send an email to the user to confirm
// their purchase. Since it's an HTML email, we've stored it in a
// view, and can pass the necessary data to it.
$email = $this->load->view('emails/receipt', $data, TRUE);
63. // At this point we send an email reminder to the customer, informing them
// that their subscription will expire soon.
// However, don't send an email if today is a Monday or Thursday, because
// the client's "really tech-saavy" cousin told them that people don't
// read their email on those days.
// @SEE: Ticket #138 - http://projects.visualchefs.com/tickets/138
66. /**
* Get the number of comments for a user
*
* @param int $user_id
* @return int
*/
public function comment_count($user_id)
{
// @TODO
}
/**
* Get a user's comments
*
* @param int $user_id
* @param int $limit
* @return array
*/
public function comments($user_id, $limit = 100)
{
// @TODO
}
67. /**
* Get a user's comments, or just a count of their comments.
*
* @param int $user_id
* @param int $limit
* @param bool $count_only
* @return int|array
*/
public function comments($user_id, $limit = 100, $count_only = FALSE)
{
// @NOTE: It's difficult to tell what the function does by its name
// @NOTE: It also does too many things
// @NOTE: I can't remember what the parameters are
}
68. /**
meh...
* Get a user's comments, or just a count of their comments.
*
* @param int $user_id
* @param int $limit
* @param bool $count_only
* @return int|array
*/
public function comments($user_id, $limit = 100, $count_only = FALSE)
{
// @NOTE: It's difficult to tell what the function does by its name
// @NOTE: It also does too many things
// @NOTE: I can't remember what the parameters are
}
72. // Set the value in Redis if it doesn't already exist
// @SEE: http://redis.io/commands/setnx
73. Summary
๏ Documentation is easier when done first
๏ Give as much insight as you can
๏ Write those friggin' docblocks!
๏ Be verbose
๏ Link to external docs when possible
78. Sample
1. User fills out the registration form
2. User clicks submit
3. Form is submitted via Ajax
1. Form data is validated
1. If valid, account is created
2. JSON response is returned with success flag, and array of errors if invalid data
4. If successful, user is redirected to the dashboard
1. If not successful, list of errors are shown
110. Summary
๏ Have a plan
๏ Simplicity
๏ Keep a README file
๏ Use a style guide
๏ Keep packages organized with tools like Sparks and
Composer
๏ Write tests
127. // Put this in index.php
require 'vendor/autoload.php';
// Call a class and it will be loaded automatically
$response = HttpfulRequest::get('http://eecoder.com/')->send();