在app \ Controller \ CarrierController.php中
<?php
class CarriesController extends AppController {
public function index(){
if($this->request->is('post')){
$this->Carries->create();
if ($this->Carries->save($this->request->data)) {
$this->Session->setFlash(__('Your contact has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('Unable to add your contact.'));
}
}
}
}
和它的模型是// // Carriers.php ///// carriers是插入表名字段
<?php
class Carriers extends AppModel{
public $useTable='carriers';
}
?>
最后是视图app \ View \ Carries \ index.cpt
<h1>welcome to Carriers</h1>
<br />
<br/>
<?php echo $this->Form->create('Carriers', array('enctype' => 'multipart/form-data'));?>
<table>
<tr><h3>Register here</h3></tr>
<tr><td>F.Name</td><td><?php echo $this->Form->text('fname'); ?></td></tr>
<tr><td>L.Name</td><td><?php echo $this->Form->text('lname');?></td></tr>
<tr><td>Date Of Birth</td><td><?php echo $this->Form->date('dob');?></td></tr>
<tr><td>Degree</td><td><?php echo $this->Form->select('field', array('options' => array('B.E','B.sc','Mca','Mtech','Mba'),'empty' => '(choose)')); ?></td></tr>
<tr><td>Sex</td><td><?php
$options=array('M'=>'Male','F'=>'Female');
$attributes=array('legend'=>false);
echo $this->Form->radio('gender',$options,$attributes);
?></td></tr>
<tr><td><?php echo $this->Form->input('Carriers.Resume', array('between'=>'<br />','type'=>'file'));?></td></tr>
<tr><td><?php echo $this->Form->end('Apply');?></td></tr>
</table>
这里出现错误
如文档中所示:
模型类名称为单数和CamelCased。
如果您有数据库表,carriers
则模型名称为Carrier
。
控制器文件在问题中是单数的,如果url是/carrier/xxx
(并且类存在),则该文件将起作用-因为CakePHP不会对url应用任何变形魔术。
但是,预期的url为:(/carriers/xxx
即,控制器名称为复数)。在问题中,文件名是单数,类名是错字:
in app\Controller\CarrierController.php
^^^^^^^
class CarriesController
^^^^^^^
CakePHP不会在名称错误的文件中找到类,也不会使用在正确位置但名称错误=的类。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句