2014-10-30 57 views
0

我需要显示在我的编辑的观点一些字段,但使它所以它们不能被编辑CakePHP的表单字段/

<div class="users form"> 
<?php echo $this->Form->create('User'); ?> 
<fieldset> 
    <legend><?php echo __('Edit User'); ?></legend> 

<?php 
    echo $this->Form->input('ID'); 
    echo $this->Form->input('username'); 
    echo $this->Form->input('account_type'); 
?> 
</fieldset> 

<?php echo $this->Form->end(__('Submit')); ?> 
</div> 

有什么方法可以让使用的;阿贝尔()函数或任何东西,所以当我在视图中显示id和帐户类型,这些字段的值出现,但无法编辑?

+0

请注意'ID'!='id'。你应该试着坚持这里的习俗。 – mark 2014-11-09 03:06:34

回答

2

您可以使用纯html输入标签的禁用属性。

echo $this->Form->input('account_type', array('disabled'=>'disabled')); 
2

您的表单中有几个错误。

  1. 的ID应该为可编辑
  2. id字段真的是大写吗? (这里的情况很重要)

好吧,现在如果你希望你的输入能够被编辑,你可以通过@Abhishek告诉的禁用属性来强制它。但是你必须把它设置为false。所以你的表格应该是这样的:

<div class="users form"> 
<?php echo $this->Form->create('User'); ?> 
<fieldset> 
    <legend><?php echo __('Edit User'); ?></legend> 

<?php 
    echo $this->Form->input('id', array('disabled'=>false)); 
    echo $this->Form->input('username', array('disabled'=>false)); 
    echo $this->Form->input('account_type', array('disabled'=>false)); 
?> 
</fieldset> 

<?php echo $this->Form->end(__('Submit')); ?> 
</div>