CakePHP Setup and Configuration
Configure for Use

Read a config variable using:

  Configure::read('Company.Name')
Database Configuration

Edit file [cakephp]/app/Config/database.php:

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'port' => '',
    'login' => 'acmeusr',
    'password' => 'c4k3-rUl3Z',
    'database' => 'acme_cakephp_db',
    'schema' => '',
    'prefix' => '',
    'encoding' => 'utf8'
);
Email Configuration

Edit file [cakephp]/app/Config/email.php:

class EmailConfig {
 
    public $default = array(
        'transport' => 'Mail',
        //'from'    => Configure::read('Company.Email'),
        'from'      => 'info@acme.com', 
        'charset'   => 'utf-8',
        'headerCharset' => 'utf-8',
    );
 
    public $smtp = array(
        'transport'  => 'Smtp',
        //'from'     => array('site@localhost' => 'My Site'),
        //'from'     => array(Configure::read('Company.Email') => Configure::read('Company.Name')),
        'from'       => array('info@acme.com' => 'Acme Inc'),
        'host'       => 'localhost',
        'port'       => 25,
        'timeout'    => 30,
        //'username' => 'user',
        //'password' => 'secret',
        'username'   => null,
        'password'   => null,
        'client'     => null,
        'log'        => false,
        'charset'    => 'utf-8',
        'headerCharset' => 'utf-8',
    );
 
    public $fast = array(
        //'from'      => 'you@localhost',
        //'from'      => Configure::read('Company.Email'),
        'from'        => 'info@acme.com', 
        'sender'      => null,
        'to'          => null,
        'cc'          => null,
        'bcc'         => null,
        'replyTo'     => null,
        'readReceipt' => null,
        'returnPath'  => null,
        'messageId'   => true,
        'subject'     => null,
        'message'     => null,
        'headers'     => null,
        'viewRender'  => null,
        'template'    => false,
        'layout'      => false,
        'viewVars'    => null,
        'attachments' => null,
        'emailFormat' => null,
        'transport'   => 'Smtp',
        'host'        => 'localhost',
        'port'        => 25,
        'timeout'     => 30,
        //'username'  => 'user',
        //'password'  => 'secret',
        'username'    => null,
        'password'    => null,
        'client'      => null,
        'log'         => true,
        'charset'     => 'utf-8',
        'headerCharset' => 'utf-8',
    );
 
    /*
    // To use this feature, you will need to have the SSL configured in your PHP install.
    public $gmail = array(
        'host'      => 'ssl://smtp.gmail.com',
        'port'      => 465,
        'username'  => 'my@gmail.com',
        'password'  => 'secret',
        'transport' => 'Smtp'
    );
    // or using TLS SMTP
    public $gmail = array(
        'host'      => 'smtp.gmail.com',
        'port'      => 465,
        'username'  => 'my@gmail.com',
        'password'  => 'secret',
        'transport' => 'Smtp',
        'tls'       => true
    );
    */
 
}
Setup AppController

Edit file [cakephp]/app/Controller/AppController.php:

App::uses('Controller', 'Controller');
App::uses('SessionComponent', 'Controller/Component');
App::uses('SessionHelper', 'Controller/Component'); 
App::uses('AuthHelper ', 'Controller/Component'); 
 
class AppController extends Controller 
{
    public $components = array(
        'Session',
        'Auth' => array(
            //'loginRedirect' => array('controller' => 'articles', 'action' => 'index'),  // at login, go to Articles list
            'loginRedirect'  => array('controller' => 'pages', 'action' => 'display', 'home'),  // at login, go to Home
            //'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
            'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),  // at logout, go to Home
            'authError'      => 'You must be logged in to view this page.',
            'loginError'     => 'Invalid Username or Password entered, please try again.',
            'authorize' => array('Controller')
        ),
        'DebugKit.Toolbar',    // see https://github.com/cakephp/debug_kit for more details
    );
 
    // only allow the login controllers only
    public function beforeFilter() 
    {
        $this->Auth->allow('login');
    }
 
    public function isAuthorized($user) 
    {
        // Here is where we should verify the role and give access based on role
        //return true;
 
        // Admin can access every action
        if (isset($user['role']) && $user['role'] === 'admin') 
        {
            return true;
        }
 
        // Default deny
        return false;
    }
}
Setup UserController

Edit file [cakephp]/app/Config/routes.php to include custome routes:

// ###--- Custom Routes ---###    
// Let us modify the core components of CakePHP to support the UserController login module. 
// First, we need to modify routes.php so that we can have a custom link for login, logout 
// and the dashboard. This step is not required but I do it so that the URLs look clean.
Router::connect('/dashboard', array('controller' => 'users', 'action' => 'index'));
Router::connect('/login',     array('controller' => 'users', 'action' => 'login'));
Router::connect('/logout',    array('controller' => 'users', 'action' => 'logout'));
 
// We also need to modify the home page so that it now points to the UserController login action.
//Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));  // default
Router::connect('/', array('controller' => 'users', 'action' => 'login'));  
Install Basic Components/Plugins

DebugKit

Articles

Authentication

AuthorizeNetComponent

Add component references to the controller using it:

<?php
  class MyController extends AppController
  {
    var $name = 'MyController';
    $components = array('AuthorizeNet', ...);
    ...
  }
?>

Use it. Call the component from the controller needing it:

<?php
  class MyController extends AppController
  {
    ...
    function chargeCard()
    {
      // You would need to add in necessary information here from your data collector
      $billinginfo = array("fname"   => "First", 
                             "lname"   => "Last", 
                             "company" => "Acme Inc.", 
                             "address" => "123 Fake St. Suite 0", 
                             "city"    => "City", 
                             "state"   => "ST", 
                             "zip"     => "90210", 
                             "country" => "USA"); 
 
        $shippinginfo = array("fname"   => "First", 
                              "lname"   => "Last", 
                              "company" => "Acme Inc.", 
                              "address" => "123 Fake St. Suite 0", 
                              "city"    => "City", 
                              "state"   => "ST", 
                              "zip"     => "90210", 
                              "country" => "USA");
      $response = $this->AuthorizeNet->chargeCard('########', '##############', '4111111111111111', '01', '2010', '123', true, 110, 5, 5, "PurchaseofGoods", $billinginfo, "customeremail@example.com", 555-5555", $shippinginfo);
    }
  }
?>

The call to the component function chargeCard uses the following format:

$response:Array = $this->AuthorizeNet->chargeCard($loginid:String, $trankey:String, $ccnum:String, $ccexpmonth:String, $ccexpyear:String, $ccver:String, $live:Boolean, $amount:Number, $tax:Number, $shipping:Number, $desc:String, $billinginfo:Array, $email:String, $phone:String, $shippinginfo:Array);

PARAMETERS

RESPONSE

The response is an array of all the response codes from Authorize.net's system. Details on all these responses is available at http://developer.authorize.net/guides/AIM/. Here are some of the most important fields:

    $response[1] = Response Code (1 = Approved, 2 = Declined, 3 = Error, 4 = Held for Review) 
    $response[2] = Response Subcode (Code used for Internal Transaction Details) 
    $response[3] = Response Reason Code (Code detailing response code) 
    $response[4] = Response Reason Text (Text detailing response code and response reason code) 
    $response[5] = Authorization Code (Authorization or approval code - 6 characters) 
    $response[6] = AVS Response (Address Verification Service response code - A, B, E, G, N, P, R, S, U, W, X, Y, Z)
                    (A, P, W, X, Y, Z are default AVS confirmation settings - Use your Authorize.net Merchant Interface to change these settings)
                    (B, E, G, N, R, S, U are default AVS rejection settings - Use your Authorize.net Merchant Interface to change these settings)
    $response[7] = Transaction ID (Gateway assigned id number for the transaction) 
    $response[38] = MD5 Hash (Gateway generated MD5 has used to authenticate transaction response) 
    $response[39] = Card Code Response (CCV Card Code Verification response code - M = Match, N = No Match, P = No Processed, S = Should have been present, U = Issuer unable to process request)

TCPDF

For example:

StringUtils

SVGGraph

PHPExcel

In PhpExcel helper, edit function createdWorksheet() to look like this:

public function createWorksheet() {
    // load vendor classes
    App::import('Vendor', 'PHPExcel');  // <-- Check class name
 
    $this->_xls = new PHPExcel();
    $this->_row = 1;
 
    return $this;
}

In controller, add references to helper:

class MyController extends AppController 
{
   ...
   public $helpers = array('Html', 'Form', 'Session', ..., 'PhpExcel');  
   ...
}   

In controller, add action to generate data:

...
function actionGetData($id)
{
    $data = ClassRegistry::init('Customer')->find('all', array(
                'conditions' => array('Customer.id' => $id),
            )); 
 
    $this->set('data', $data); 
 
    // Create a view that does not display any html header code except for the Excel data.
    // To do this, set the layout to be 'ajax', which just happens to contain no html outside the main content.
    $this->layout = 'ajax';
}    

Create view. Eg: actiongetdata

// create new empty worksheet and set default font
$this->PhpExcel->createWorksheet()->setDefaultFont('Calibri', 12);
 
// define table cells
$table = array(
    array('label' => __('User'), 'filter' => true),
    array('label' => __('Type'), 'filter' => true),
    array('label' => __('Date')),
    array('label' => __('Description'), 'width' => 50, 'wrap' => true),
    array('label' => __('Modified'))
);
 
// add heading with different font and bold text
$this->PhpExcel->addTableHeader($table, array('name' => 'Cambria', 'bold' => true));
 
// add data
foreach ($data as $d) {
    $this->PhpExcel->addTableRow(array(
        $d['User']['name'],
        $d['Type']['name'],
        $d['User']['date'],
        $d['User']['description'],
        $d['User']['modified']
    ));
}
 
// close table 
$this->PhpExcel->addTableFooter();
 
// Save to Excel file
ob_end_clean();  // remove all output (very important, otherwise data is garbage)
this->PhpExcel->output('MyExcelFile.xlsx');
Delete Cached Models

After updating a model, clear the cache to see the changes on the site.

$ rm -f /app/tmp/cache/models/cake_model_*
$ rm -f /app/tmp/cache/persistent/cake_core_*