Criki – the creation of a wiki with CakePHP, Part 2

Published on and tagged with cakephp  ibm  tutorial

On IBM’s developerWorks the second part of the series “Create an interactive production wiki using PHP” has been published. It deals with user registration and custom markup rendering.

I am not so happy with this part. First, it uses functions of the HTML helper which are deprecated since version 0.9.2 of CakePHP, like passwordTag() and submitTag() (you should use password() resp. submit() instead). And second, I think the rendering of the markup shouldn’t be done in the controller. It should be done in a component or a helper (depends on whether you look at it as business logic or presentation logic). The advantages:

  • the code would be easier to test
  • the controller would be easier to read
  • the markup rendering could be reused

Anyway, here the links to the article: article (registration needed), PDF

Part 1

6 comments baked

  • Seth

    You said “I think the rendering of the markup shouldn’t be done in the controller.”

    I was wondering if you could elaborate a little more, or provide a counter-example. After poking around through the source code, and being new to CakePHP, I couldn’t figure out what you meant by that.

  • cakebaker

    @Seth: Sure. Look at EntriesController::view(), in this function the parsing of the wiki document happens. If this functionality is put to a component, this function could look like:

    function view($title = null) {
      if(!$title) {
        $this->Session->setFlash('Invalid Entry.');
      $entry = $this->Entry->findByTitle($title);
      if ($entry) {
        $content = $entry['Entry']['content'];
        $this->set('entry', $this->Parser->parse($content));
      } else {
        $this->redirect('/entries/edit/' . preg_replace("/[^a-z]/", '', strtolower($title)));

    I hope you see what I mean :)

  • duane

    At the beginning of Part 5 (completed last week, but I don’t have a timetable for when they will publish it), the Wiki markup is moved off to a helper. I didn’t have wordcount to cover helpers available in Part 2, though I should have covered it in Part 3.

    Ultimately, that’s the direction it goes though.

  • cakebaker

    @duane: That’s good to hear, I am looking forward for the next installments of this series.

  • Seth

    @cakebaker: Thanks for taking the time to explain that. I feel Cake’s docs are a bit lacking and sometimes inconsistent (in addition to 99% of the tutorials using mixtures of current and deprecated code) so it’s been difficult for me to pick up on things.

    Love the site!

  • Muhammad Hassan

    Thank you for this tutorial.
    Muhammad Hassan

© daniel hofstetter. Licensed under a Creative Commons License