0

I am pretty a green hand in CakePHP programming, I have a question on FormHelper usage -

If we use FormHelper at View, it will output some HTML codes and all these codes are defined in CakePHP (I think). The question is, all these codes are not as same as the HTML Template I already had, so I need to change HTML Template including html and css to comply to FormHelper convention. For me, it's a lot works.

I am wondering, when I started to make a website, commonly I will get all templates from the designer, but the designer make all html themselves and they don't know CakePHP convention at all, so how can I make all templates easier applied to CakePHP?

Customize FormHelper html template? Or just abandon them?

4

1 に答える 1

0

The output from CakePHP's form helper is pretty customisable out of the box. The basic format of a field looks like this:

<div class='input extra classes'>
<label for='control_id'>Label</label>
<input id='control_id' name='control_name'/>
<div class='error'>Validation error message</div>
</div>

Which is just about the minimum markup you can get away with to style up any form element.

You can inject additional markup using the 'before', 'between', 'after' etc. options of Form::input();

Of course, you don't HAVE to use the form helper (although it takes a lot of dog work out of making forms). You can just past the raw HTML for your form into the view.

The problem with this is that you won't see the error messages generated when validation fails and you will also need to make sure you use the exact naming conventions for the input name attribute to make sure your form works with Cake's validation.

An easy way to do this is to just add a regular echo $this->Form->input() to your page and copy the name attribute in generates into your html markup.

All this being said, I don't always do my own markup and have yet to receive markup from a 3rd party that couldn't be mimicked with Cake's Form helper and some CSS.

If you post an example of the form you are trying to re-create we could have a better crack at answering this question in better detail.

于 2013-02-07T09:34:12.947 に答える