Inflector :: humanize($ key)将加入日期转换为加入日期

时间:2009-08-31 06:32:06

标签: php cakephp

我有一个表格,我提交的内容就像使用

一样
function submit($formid = null, $fillerid = null){
    $this->data['Result']['form_id'] = $formid;
    $this->data['Result']['submitter_id'] = $fillerid;
    $this->data['Result']['submitter'] = $this->Session->read('filler');
    echo "submitter: " . $this->Session->read('filler');
    $results = $this->Form->hasResults($this->data);
    //echo http_build_query($_POST);

    if(empty($results)){
        foreach($_POST as $key => $value):
            if(is_array($value)){
                $value = implode('', $_POST[$key]);
                $this->data['Result']['value'] = $value;
            }else{
                $this->data['Result']['value'] = $value;
            }
            $this->data['Result']['form_id'] = $formid;
            $this->data['Result']['submitter_id'] = $fillerid;
            $this->data['Result']['label'] = Inflector::humanize($key);

            $this->data['Result']['submitter'] = $this->Session->read('filler');
            $this->Form->submitForm($this->data);
        endforeach;

        $this->Session->setFlash('Your entry has been submitted.');
    }
}

我有一个类似的事情

  <form method="post" action="/FormBuilder/index.php/forms/submit/1/4" id="ResultSubmit"> 

  <div class="input text"><label for="1">Firstname</label><input type="text" value="" style="width: 300px;" id="1" name="Firstname"/></div>  <br/>




  <div class="input text"><label for="2">Last Name</label><input type="text" value="" style="width: 300px;" id="2" name="Last Name"/></div>  <br/>




  <div class="input text"><label for="3">Age</label><input type="text" value="" style="width: 200px;" id="3" name="Age"/></div>  <br/>
       <center>  <span id="errmsg3"/> </center>



  <div class="input textarea"><label for="4">Address</label><textarea style="height: 300px;" id="4" rows="6" cols="30" name="Address"/></div>  <br/>



  <div class="input text"><label for="5">Date Of Joining</label><input type="text" value="" style="width: 300px;" id="5" name="Date of joining"/></div><br/>


  <div class="input text"><label for="6">Email - Id</label><input type="text" value="" style="width: 300px;" id="6" name="Email - id"/></div>  <br/>




  <div class="input text">
<label for="7">Personal Number</label><input type="text" value="" maxlength="3" style="width: 30px;" id="7" name="Personal Number[]"/><input type="text" value="" style="width: 30px;" maxlength="3" id="7-1" name="Personal Number[]"/><input type="text" value="" style="width: 70px;" maxlength="4" id="7-2" name="Personal Number[]"/></div>

 <span id="errmsg7"/> 
  <br/>




  <div class="input select"><label for="8">Gender</label><select id="8" name="Gender">

MaleFemale

  <div class="input text"><label for="9">Official Number</label><input type="text" value="" style="width: 200px;" id="9" name="Official Number"/></div><br/>


     <div class="input select"><label for="10">Experience</label><select id="10" name="Experience">
    <option value="Fresher">Fresher</option><option yrs="" 5="" value="Below">Below 5 Yrs</option><option yrs="" 10="" value="Above">Above 10 yrs</option></select></div><br/>



         

实际上我的输入名称为

  • 姓氏
  • 年龄
  • 地址
  • 加入日期
  • 电子邮件 - 身份
  • 个人号码
  • 性别
  • 官方编号

但是当我使用Inflector :: humanize($ key)来保存具有空格字符的名称时,它们已经转换为类似于加入日期,即。,O和J变为大写字母...但我需要保存它们如加入日期.. 怎么办???

1 个答案:

答案 0 :(得分:0)

你必须编写自己的方法来实现这一目标。如果你想大写字符串的第一个字符,可以使用Inflector :: humanize()代码并用ucfirst()替换ucwords():

function humanize($lowerCaseAndUnderscoredWord) {  
    return ucfirst(str_replace("_", " ", $lowerCaseAndUnderscoredWord));  
}