Roshan Book

My Tech Notebook

Tag Archives: cakephp

Deploying cakephp on hostgator method 2

Source:http://www.balistupa.com/blog/2010/11/how-to-install-cakephp-on-hostgator-shared-hosting/

Another helpful link :http://bakery.cakephp.org/articles/gedm/2009/08/29/installing-cakephp-on-shared-hosting

I just buy new shared hosting account for my new domain on hostgator. I want to install cakephp web application into this hosting. However the local setting or common setting that i used on other hosting is not work on hostgator. After figure out the problem, i found that the hostgator hosting does not allow for changing DOCUMENT ROOT setting.

So after research on cakephp tutorial, which come to setting cakephp on shared hosting and i think this solution also good for production phase. I will mention how i set my cakephp on hostgator

  1. move app, cake, plugins, vendors folder into your hosting root folder. It is user root folder on your hosting
  2. delete .htaccess and index.php on cakephp root folder
  3. move /app/webroot/*.* to /public_html folder
  4. delete empty /app/webroot folder
  5. edit /public_html/index.php to point to the ‘cake’ and ‘app’ directories. For example my public_html path for my domain is /home/myhost/public_html, so i point
    – ROOT to look at /home/myhost
    – APP_DIR to look at /home/myhost/app
    – CAKE_CORE_INCLUDE_PATH to look at /home/myhost/cake
  6. edit this line on /public_html/index.php with your appropriate path
    if (!defined('ROOT')) {
    define('ROOT', DS.'home'.DS.'myhost');
    }

    if (!defined('APP_DIR')) {
    define('APP_DIR', 'app');
    }

    if (!defined('CAKE_CORE_INCLUDE_PATH')) {
    define('CAKE_CORE_INCLUDE_PATH', DS.'home'.DS.'myhost');
    }

  7. The only .htaccess i have on /home/myhost/public_html, the setting for .htaccess look like this
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    </IfModule>
Advertisements

Deploying cakephp on hostgator

I’m having trouble with uploading my cakePHP project on a shared hosting ( from hostgator ). Here is what I have done: I’ve organized my cake distribution like this:

  • home/user/app
  • home/user/cake/cake
  • home/user/cake/vendors
  • home/user/cake/.htaccess
  • home/user/cake/index.php

    I have taken the content of webroot directory from app and put it in

    • home/user/public_html

    I’ve modified this file home/user/public_html/index.php ( the one that was in app/webroot ) changing these lines like this:

    • define(‘ROOT’, DS.’home’.DS.’user’);
    • define(‘APP_DIR’, ‘app’);
    • define(‘CAKE_CORE_INCLUDE_PATH’, DS.’home’.DS.’user’.DS.’cake’);

    And that’s about it.

    MY PROBLEM IS THE FOLLOWING:

    I have managed to deal with all the problems involved in the default index.php cakePHP page and I have a green and fully functional so to say, project. So when I access my “/”, I get:

    “Your tmp directory is writable.

    The FileEngine is being used for caching. To change the config edit APP/config/core.php

    Your database configuration file is present.

    Cake is able to connect to the database.”

    Now, I’ve created a model-view-controller with a mysql database background (like in the 15 min Blog Tutorial ), but when I’m trying to access some views ( e.g. /posts )…it gives me a blank page ( this worked perfect on my local machine virtual server apache ).

    What configuration am I missing ?

    Thank you.

EDIT: Apparently I had problems with the hosting. My URL was something like:

http://gator111.hostgator.com/~username/

and all I had to do was add an extra line in the webroot .htaccess:

RewriteBase /~username/

Thanks for the support.

Cakephp

Tools

1.Bake Tool :
Use :

a) Baking an application – cake bake application name

b) Database configuration – cake bake db_config

c) Baking Model – cake bake model

d) Baking controller – cake bake controller

e) Baking view – cake bake view

f) Getting the help – cake bake help

2. Controller :

Naming Convention

a) File name – tablename_tablename2_controller.php

b) Class name in file name in camel case like – class TablenameTablename2Controller extends AppController

3. Views

Each controller function will have a separate view. And that view is called inside the layout to generate the page.

Ina controller we use the set() method to send data from your controller to your view.

$this->set(‘color’,’pink’)

Once you’ve set(), the variable can be accesses in your view.

<?php echo $color ?> displays pink

4. Associations

It comes naturally

Relationship Association Type Example
one to one hasOne A user has one profile
one to many hasMany Users in a system can have multiple recipies
many to one belongsTo A recipe belongs to a user
many to many hasAndBelongsToMany Recipes have, and belong to many tags

 

5. Layouts

Any view can have as many layouts as needed

$content_for_layout variable include view for that layout

$title_for_layout has title variable

6. Schema Tool

Uses : adding Columns, Altering Columns,Deleting Columns and Version Control

cake schema generate –fgenerate schema file for all tables with or without model with following options

Overwrite- Overwrite schema.php

Snapshot – increment schema.php

Quit

So when you select Snapshot it generates schema_2.php

Run numbered migration : cake schema run update –s2

Where 2 is the Snapshot number you wish to run

Rebuild the database : cake schema run create

Sql Dump file: cake schema dump filename.sql

 

8. Helper

HTML and FORM are default helper always available

Others helpers are Ajax, Javascript,Pagination

It is reusable between View Template, Layouts and elements

Best is when it is chosen by Controller

To enable a helper in your view

$helpers=array(‘Form’,’Html’,’Javascript’,’Time’);

You can also add helpers from within action

$this->helpers[]=’Time’

To create a custom helper

inside /app/views/helpers

class LinkHelper extends AppHelper{

function link_edit($title,$url){

//create specually formatted link

}

}

9. Element

This is like include file for the website. lives in /app/views/elements/

Filename extention is .ctp

Elements which live in generally are Ads,help boxes,navigational controls,extra menus,forms, and callouts

Calling element inside view or layout

<?php echo $this->element(‘help’); ?>

 

10. CRUD

Create row in table – $this->Post->save($this->data)

Read rows from table – $this->Post->find(‘all’)

Update row in table – $this->Post->save($this->data)

Delete row from table – $this->Post->del($id)

11. Validation

In model

var $validate=array(

‘login’=>array(‘alphaNumeric’=>array(‘rule’=>’alphaNumeric’,’required’=>true,’message’=>’alphabets and numbers only’

)

)

 

12. Behaviour

Shared between models

13. Cakephp_OOP

Placed in /project_name/vendors/directory

14. Component

Shared between controllers

15. Route

Router::connect(

‘/blog/:action/*’,

array(‘controller’=>’posts’,’action’=>’index’)

)

%d bloggers like this: