在CakePHP中的视图(.ctp文件)中应用PURE html

时间:2015-01-30 02:19:06

标签: html cakephp cakephp-1.3

我只是想问一下是否可以用纯HTML创建一个ctp文件?例如,我想添加一个表单,我的代码将是:

<form>First name:<br><input type="text" name="firstname"><br>Last name:<br><input type="text" name="lastname"></form>

而不是这样:

<?php echo $this->Form->create('User');?>
<fieldset>
    <legend><?php __('Add User'); ?></legend>
<?php
    echo $this->Form->input('lastname');
    echo $this->Form->input('firstname');
    echo $this->Form->input('email');
    echo $this->Form->input('organizer_pic');
    echo $this->Form->input('description');
    echo $this->Form->input('website');
    echo $this->Form->input('company');
    echo $this->Form->input('organization');
    echo $this->Form->input('contact_num');
    echo $this->Form->input('username');
    echo $this->Form->input('password');
    echo $this->Form->input('group_id');
?>
</fieldset><?php echo $this->Form->end(__('Submit', true));?>

你们认为这有可能吗?我希望它是纯HTML,因为我很难用Bootstrap创建一个好的布局。我正在使用CakePHP 1.3。如果您有任何想法,请告诉我。

3 个答案:

答案 0 :(得分:1)

你可以在ctp文件上使用纯HTML,但你也需要在你的控制器中有一个动作。您可以将操作留空。

答案 1 :(得分:-1)

You should try this
<div class="row">
                    <div class="col-md-6">
                <?php echo $this->Form->create('User');?>
                <fieldset>
                    <legend><?php __('Add User'); ?></legend>
                    <div class="form-group has-feedback">
                                    <label>Username</label>
                                    <?php echo $this->Form->input('lastname',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                   </div>
                   <div class="form-group has-feedback">
                                    <label>firstname</label>
                                    <?php echo $this->Form->input('firstname',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                    <div class="form-group has-feedback">
                                    <label>Email</label>
                                    <?php echo $this->Form->input('email',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                     <div class="form-group has-feedback">
                                    <label>organizer_pic</label>
                                    <?php echo $this->Form->input('organizer_pic',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                    <div class="form-group has-feedback">
                                    <label>description</label>
                                    <?php echo $this->Form->input('description',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                     <div class="form-group has-feedback">
                                    <label>website</label>
                                    <?php echo $this->Form->input('website',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                     <div class="form-group has-feedback">
                                    <label>company</label>
                                    <?php echo $this->Form->input('company',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                     <div class="form-group has-feedback">
                                    <label>organization</label>
                                    <?php echo $this->Form->input('organization',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                    <div class="form-group has-feedback">
                                    <label>contact number</label>
                                    <?php echo $this->Form->input('contact_num',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                    <div class="form-group has-feedback">
                                    <label>username</label>
                                    <?php echo $this->Form->input('username',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                     <div class="form-group has-feedback">
                                    <label>password</label>
                                    <?php echo $this->Form->input('password',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                     <div class="form-group has-feedback">
                                    <label>group id</label>
                                    <?php echo $this->Form->input('group_id',array('class'=>'form-control','label'=>false,'div'=>false));
                                    ?>
                                    <i class="icon-users form-control-feedback"></i>
                    </div>
                     <div class="form-group has-feedback">
                     <?php
                     echo $this->Form->button('Submit',array('class'=>'btn btn-success btn-xs','div'=>false),array('escape'=>false)
                            );
                     ?>
                     </div>
                </fieldset><?php echo $this->Form->end();?>
                </div>
                </div>

输出

enter image description here

Html输出

<div class="col-md-6">
                               <form action="/BTSSO/Users/demo/" id="UserDemoForm" method="post" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST"/></div>            <fieldset>
                      <legend></legend>
                      <div class="form-group has-feedback">
                                      <label>Username</label>
                                      <input name="data[User][lastname]" class="form-control" type="text" id="UserLastname"/>                                <i class="icon-users form-control-feedback"></i>
                     </div>
                     <div class="form-group has-feedback">
                                      <label>firstname</label>
                                      <input name="data[User][firstname]" class="form-control" type="text" id="UserFirstname"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                      <div class="form-group has-feedback">
                                      <label>Email</label>
                                      <input name="data[User][email]" class="form-control" type="email" id="UserEmail"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                       <div class="form-group has-feedback">
                                      <label>organizer_pic</label>
                                      <input name="data[User][organizer_pic]" class="form-control" type="text" id="UserOrganizerPic"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                      <div class="form-group has-feedback">
                                      <label>description</label>
                                      <input name="data[User][description]" class="form-control" type="text" id="UserDescription"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                       <div class="form-group has-feedback">
                                      <label>website</label>
                                      <input name="data[User][website]" class="form-control" type="text" id="UserWebsite"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                       <div class="form-group has-feedback">
                                      <label>company</label>
                                      <input name="data[User][company]" class="form-control" type="text" id="UserCompany"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                       <div class="form-group has-feedback">
                                      <label>organization</label>
                                      <input name="data[User][organization]" class="form-control" type="text" id="UserOrganization"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                      <div class="form-group has-feedback">
                                      <label>contact number</label>
                                      <input name="data[User][contact_num]" class="form-control" type="text" id="UserContactNum"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                      <div class="form-group has-feedback">
                                      <label>username</label>
                                      <input name="data[User][username]" class="form-control" maxlength="255" type="text" id="UserUsername" required="required"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                       <div class="form-group has-feedback">
                                      <label>password</label>
                                      <input name="data[User][password]" class="form-control" type="password" id="UserPassword" required="required"/>                                <i class="icon-users form-control-feedback"></i>
                      </div>
                       <div class="form-group has-feedback">
                                      <label>group id</label>
                                      <select name="data[User][group_id]" class="form-control" id="UserGroupId">
                          </select>  <i class="icon-users form-control-feedback"></i>
                      </div>
                         <div class="form-group has-feedback">

                   <button class="btn btn-success btn-xs"  type="submit">Submit</button>                        </div>
                  </fieldset>
            </form>            
            </div>

答案 2 :(得分:-2)

<form action="/project_name/users/add" id="UserAddForm" method="post">
   First name:<br>
   <input type="text" name="data[User][firstname]"><br>
   Last name:<br>
   <input type="text" name="data[User][lastname]"><br>
   <input type="submit" value="Submit">
</form>

我认为这不是推荐的解决方案

如果需要在input()方法的输出中注入一些标记,请使用这些键:

echo $this->Form->input('field', array(
    'before' => '--before--',
    'after' => '--after--',
    'between' => '--between---'
));

输出:

<div class="input">
--before--
<label for="UserField">Field</label>
--between---
<input name="data[User][field]" type="text" value="" id="UserField" />
--after--
</div>

可以参考以下链接进行更多自定义

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options