Question about sample blog tutorial

I am just learning CakePHP and worked through the sample blog tutorial. My question is about the index view created here. After creating the code to "add" a post, the instructions call for this line to create the "Add Post" link on the index:


<?php echo $this->Html->link('Add Post', array('controller' => 'posts', 'action' => 'add')); ?>

Later in the tutorial the 'controller' => 'posts' portion of the array is gone from this link, and not included in the other links. Was this originally included just to remove ambiguity and is not necessarily needed?

The program runs properly without this piece, but I am curious if I should be including the 'controller' reference in my code as a matter of best practice.

Thanks,

Joe

Asked by gatorjoe, on 8/2/12

1 Answer

The "controller" and "action" are both optional. If you do not include them then the link that is generated will default to the controller and action that called the current view.

Answered by mntbkron 8/2/12

Great, thank you for the clarification!

gatorjoe - on 8/2/12

<< comments | comments >>
<< previous next >>

Rating

0

Viewed

357 times

Last Activity

on 8/2/12