Hello World in CakePHP – 3 steps

Posted by – April 13, 2010

  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… :-)

3 Comments on Hello World in CakePHP – 3 steps

  1. [...] I just discovered its easy enough to do hello world in CakePHP. Read more [...]

  2. mark says:

    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.

  3. @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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>