This is a PHP class to do distance andcalculations based on Zip Codes.

This will become extremely useful in certain projects where I need to calculate users/bands within a certain distance from each other.

Check it out here:</a>

This is going to be short and sweet. DateJS (JavaScript Helper) is just awesome. It is everything that I have needed for several projects.

New release is available now! Enjoy everyone!

NOTE: This is for ADVANCED users. CakePHP requires an extensive knowledgebase of PHP and Object Oriented Programming. If you are not familiar with PHP or OOP this is not for you. Try installing WordPress instead.

This is for the majority of cpanel hosting companies, especially Bluehost (The greatest cpanel hosting company out there, and that's not just an opinion).

CakePHP by default comes with the core in a folder, the same folder that the app directory is also located. This is typically considered not secure. So lets fix that. Let's put our CakePHP Core in the root of your hosting account.

Step 1. Download CakePHP from their website.

Step 2. FTP your file to the public_html directory (OR the folder your application will be), extract the file. You should have a folder that looks like the following.

Step 3. Move all the files out of the app/ folder. (The contents of the App/ folder, not the folder itself)

Step 4. Move the cakephp-cakephp-77aa960/ folder to the ~/ directory. At this point I recommend renaming it to something that takes less time to type. I will call it CakeCore.

Step 5. Inside your app/ directory that you copied the contents out of [step 3] there is a subdirectory called webroot. Edit the index.php [/webroot/index.php] file and make the following change.


    //define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
Change it to:

    define('CAKE_CORE_INCLUDE_PATH', '/home/username/CakeCore/lib');
Bluehost has the home directory as many different things. /home, /home1, /home2 , etc followed by the official cpanel/bluehost username, which you can find on the left side of your cpanel. Be sure you replace the above with YOUR information.

There should be nothing more that you have to configure. From this point on you can reuse your CakePHP Core AND get the benefit of security now that your core code cannot be touched.

This one is a simple trick, and one to remember. Add this little line to the controller (/App/Controller/UsersController.php to control how many results per page are loaded. You can also use this same method to manipulate the results in other ways as well (See this for more details.)

public $paginate = array( 'limit' => 25, 'order' => array('Post.title' => 'asc'));

This is coming directly from here. That website is out of date, and so here it is, v2.0 fresh.
I am assuming you understand routes.

In your bootstrap.php file add the following. This will instantiate CakeSession (after it's inclusion), from there you can check the status of the login and define the routes based on whether the user is logged in or not.

// include the Session Component to our application
App::uses('CakeSession', 'Model/Datasource');
// now create new SessionComponent instance
$Session = new CakeSession();
// check if the user logged in
if ($Session->read('Auth.User')) {
    // set the default routing to submissions controller
    Configure::write('Route.default', array('controller' => 'users', 'action' => 'index'));
// nope, user not logged in
else {
    // set the default routing to our login page in users controller
    Configure::write('Route.default', array('controller' => 'pages', 'action' => 'display', 'home'));
and make sure this is in your routes.php file. Comment out or remove the old line.
Router::connect('/', Configure::read('Route.default'));

This is a basic tip which comes in handy. Elements allow you to place blocks of code that are repeated or reused in your application. They also come in handy if you are just looking to tidy up that view of yours.

In this example we are going to take our login form and make it an element. Then we will call it on our page. This tip is to show how to add an element, so don't worry if you don't understand the login code. Lets name this file login.ctp and put it in our /App/View/Elements folder.

<?php echo $this->Form->create('User', array('action' => 'login'));
    echo $this->Form->input('email_address',array('label' => '', 'class'=>'span3', 'placeholder' => 'Email Address'));
    echo $this->Form->input('password',array('label' => '', 'class'=>'span3', 'placeholder' => 'password'));
    echo $this->Form->end(array('label' => 'Sign In', 'value' => 'Sign In', 'class' => 'btn btn-primary'));
And in our view file (/App/View/Pages/home.ctp or whatever View you are working on)

<?php echo $this->element('login'); ?>
That's it! You should now have the basics to including an Element in your View! Congratulations! We knew you could do it!>

Separating CakePHP App from Core.

Why would I do that?
-Easy to upgrade
-Easy to deploy new apps
-App isolation from Core

These steps should be fairly straight forward and easy to follow. The way we set it up puts the core in the root, so this will be good for local installations on mac/linux. You can set it up for a shared environment, but I will leave that for another day.

Note: This is showing CakePHP 2.1.1 but the steps are the same for later versions.

Step 1 - Download core and place files in the proper folders.
Make the initial directories. The first is what we will connect our App’s to. The second will contain the core itself.

mkdir /var/cake
mkdir ~/CoreCode
Now lets download CakePHP from and extract it to our folder. Then lets rename it to something easier to read.

cd ~/CoreCode
wget <a href="" target="_blank"></a><br />
tar -zxvf<br />
mv cakephp-cakephp-0cad237 cakephp-2.1.1
Step 2 - link the core directory to our CakePHP core.

cd /var/cake
ln -sfn ~/CoreCode/cakephp-2.1.1/ cakephp2
Now we can take the app folder from the CakePHP core (in ~/CakeCore/cakephp-2.1.1) and place it in our webroot that will broadcast our applications. This can be in a variety of places. /var/www; /var/webroot; ~/public_html and more depending on the server configuration.

cd ~/CakeCore/cakephp-2.1.1
cp -av App ~/public_html/
Note: at this point the ‘App’ folder doesn’t need to be called ‘App’ it can be named anything, or you can take it’s contents out and place them in which ever directory you desire.

Step 3 - Configure the application to the core
This is clearly the most important step. Change the Keys and connect to the database. This is normal and won’t be covered. What is different is now we will link our App to our Core. Navigate to App/Webroot and open index.php Uncomment the following line:

//define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
and change it to the following:

define('CAKE_CORE_INCLUDE_PATH', DS.'var'.DS.'cake'.DS.'cakephp2'.DS.'lib');
We should be all configured and setup now to connect properly to our core. We can repeat this step as needed. You can also download this awesome start app which includes Twitter Bootstrap (a killer CSS library) and jQuery.

Click here to download the starter app.