Quick CakePHP Tip: Prefix/Admin Routing and form->create()

Richard's picture

A quick tip to get your forms to play nice with admin routing:

/views/users/edit.ctp

<?php echo $form->create("User", array("url" => $html->url(array("admin" => true), true))) ?>

Why? For some reason, $form->create() ignores the usual routing prefix attribute ("admin"=>true) so you have to pass the url through $html->url() which does take prefix routing into account.

The last true param tells $html->url() to return an absolute url (from your site route).

Comments

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options