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

Anonymous's picture

Well, thank you man, you

Well, thank you man,
you saved me! :)

Anonymous's picture

Is there a bug report somewhere about this?

I couldn't find one.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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