Hello World in CakePHP – 3 steps

  1. Download and set up CakePHP in your webroot. Stop reading further if you cant do it or you are not sure how to do it.
  2. Create a file named “helloworld_controller.php” in folder “cakephp/app/controllers/helloworld_controller.php” and paste following code in the file
    <?php
    class HelloWorldController extends Controller {
    public $name = 'HelloWorld'; //Controller name, we need it.
    public $uses=null; //The example doesn't "use" any model.
    public $autoRender=false; //Do not render "automagically"
    public function index() {//The default action for a CakePHP controller
    echo __METHOD__;//This will print HelloWorld suffixed with some more info ;-)
    }
    }
  3. Point your browser to CakePHP installation on your server for example “http://localhost/cakephp/helloworld/”

Piece of cake… 🙂

Author: Kumar Chetan Sharma

Run of the mill developer.

4 thoughts on “Hello World in CakePHP – 3 steps”

  1. this is an incomplete echo world example
    why not using a view? following MVC principles

    /views/hello_world/index.ctp
    => put sth to echo

    public function index() {} // can stay empty

    and I would use an array here:
    $var uses = array();

    now visit
    /hello_world/

    thats all…
    more correct then the version above.

  2. @mark, agreed to your point. But you still have to create a controller. I know in an MVC framework the purists will insist upon keeping view separate from controller. But as the title says, its simple 3 steps hello world example.

Comments are closed.