题
所以我有一个叫做动作的用户控制“的 selfView 的”它看起来像这样: ( users_controller.php中)
function selfView() {
$user = $this->User->find('first', array('conditions' => array('User.id' => $this->Auth->user('id'))));
$formms = $this->Form->find('all', array('fields' => array('Form.id', 'Form.name'), 'recursive' => -1));
$this->set(compact('user', 'formms'));
$this->render('view');
}
这使得其具有在其上一种形式的简档页面。这是在第一的形式呈现在页面上,它工作得很好,你期望的那样。
查看的代码片断: (用户/ view.ctp )
<div id="passwordChange">
<?php echo $form->create('User', array( 'action' =>'updatePass' ));?>
<fieldset>
<legend><?php __('Change Password');?></legend>
<?php
$options = array('type'=>'password', 'div' => array('class' => 'required'));
echo $form->input(__('old_password', true), $options);
$options = array('div' => array('class' => 'required'), 'error' => array('confirmPassword' => __('Passwords do not match please try again',true), 'noempty' => __('Please provide a password',true)));
echo $form->input(__('password', true), $options);
$options = array('type'=>'password', 'div' => array('class' => 'required'));
echo $form->input(__('confirmation_password', true), $options);
echo $form->hidden('User.id', array('value' => $user['User']['id']));
?>
</fieldset>
<?php echo $ajax->submit(__('Change Password', true), array('url' => array('controller' => 'users', 'action' => 'updatePass'),
'update' => 'storage',
'complete' => '$("#UserUpdatePassForm input[type=password]").val(""); '));
$form->end();?>
<a href="#">Cancel</a>
</div>
的 HTML 强>所产生的形式 “的用户/ view.ctp ”:
<form action="/high-school-app/users/updatePass" method="post" id="UserUpdatePassForm">
<fieldset style="display: none;">
<input type="hidden" value="POST" name="_method">
</fieldset>
<fieldset>
<legend>Change Password</legend>
<div class="required">
<label for="UserOldPassword">Old Password</label>
<input type="password" id="UserOldPassword" value="" name="data[User][old_password]">
</div>
<div class="required required">
<label for="UserPassword">Password</label>
<input type="password" id="UserPassword" value="" name="data[User][password]">
</div><div class="required required">
<label for="UserConfirmationPassword">Confirmation Password</label>
<input type="password" id="UserConfirmationPassword" value="" name="data[User][confirmation_password]">
</div>
<input type="hidden" id="UserId" value="" name="data[User][id]">
</fieldset>
<div class="submit">
<input type="submit" onclick="return false;" id="submit2026598409" value="Change Password" update="storage">
</div>
<script type="text/javascript">
//<![CDATA[
jQuery('#submit2026598409').click( function() { jQuery('#submit2026598409').parents('form').ajaxSubmit({beforeSend:function(request) {request.setRequestHeader('X-Update', 'storage');}, complete:function(request, textStatus) {$("#UserUpdatePassForm input[type=password]").val(""); }, success:function(data, textStatus) {jQuery('#storage').html(data);}, async:true, type:'post', url:'/high-school-app/users/updatePass'}); return false;});
//]]>
</script>
<a href="#">Cancel</a>
</form>
然后,我打电话和元件,也将呈现的形式。 (用户/ view.ctp )
echo $this->element('my_apps' , array('applications' => $applications));
然后这是它一切都错了。不管我怎么努力,我不能得到这个第二种形式正确地打印出来。表格的中间部分将打印出来,只是没有开始和结束标记。随着出他们的形式是对我没用。在这一点上,我真的不想亲手写出来。
这是在我的元件,我试图使用以输出的形式的代码(元素/ my_apps.ctp ):
<?php echo $form->create('Applications', array( 'url' => array('controller' => 'applications', 'action' => 'assign', 'id' => null))); ?>
<fieldset>
<legend><?php __('Assign Application to User');?></legend>
<?php
$options = array('--' => __('Select One',true), 'test' => 'test', 'test2' => 'test2');
echo $form->label('Application.form_id', __('Form Name',true).":");
echo $form->select('Application.form_id', $options, $selected = '--');
echo $form->hidden('Application.user_id', array('value' => $user['User']['id']));
?>
</fieldset>
<?php echo $form->end(__('Assign', true));?>
这是什么 “的元素/ my_apps.ctp ” 打印出:
<fieldset style="display: none;">
<input type="hidden" value="POST" name="_method">
</fieldset>
<fieldset>
<legend>Assign Application to User</legend>
<label for="ApplicationFormId">Form Name:</label>
<select id="ApplicationFormId" name="data[Application][form_id]">
<option value=""></option>
<option selected="selected" value="--">Select One</option>
<option value="test">test</option>
<option value="test2">test2</option>
</select>
<input type="hidden" id="ApplicationUserId" value="" name="data[Application][user_id]">
</fieldset>
<div class="submit">
<input type="submit" value="Assign">
</div>
据不会打印应该是这样的开始和结束标记:
<form action="/high-school-app/applications/assign" method="post" id="ApplicationAssignForm">
.....
.....
</form>
任何想法?东西,我应该尝试做调试将是有益的。
更新
我只是试图在由手知晓的代码和甚至正在被剥离出来。是否有某种处理后走向何方?莫非是负责清除我的表单标签?
解决方案
我看不出什么错,但我可以建议你的理智,你要么在第一种形式使用不同的名称为变量$options
,或者更好的是,写在阵列内联。这是比较常见的,看惯了通过选择选项,你在第二种形式所做$options
。即节省$选项 '选项'。
在你的函数selfView()
你似乎没有赋值applications
&formms
。
我的个人的偏好是写:
<?php echo $form->submit(__('Assign', true));
echo $form->end();?>
是这样的:
<?php echo $form->end(__('Assign', true)) ?>
我认为它使代码略微更具有可读性。
其他提示
在第一个表格不呼应形式 - $>端(),因此该形式不正确关闭。
不隶属于 StackOverflow