php - 在非对象 app\Controller\CarriesController.php 第 5 行调用成员函数 create()

标签 php cakephp

在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'; 
    }
?>

最后是 View app\View\Carry\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>

这里出现错误

最佳答案

型号名称为单数

如图所示in the documentation :

Model class names are singular and CamelCased.

如果您有数据库表Carriers,则型号名称将为Carrier

保持传统

Controller 文件在问题中是单数的,如果网址是/carrier/xxx(并且该类存在),那么它将起作用 - 因为 CakePHP 不适用url 的任何变形魔法。

预期的 url 将为:/riers/xxx(即 Controller 名称是复数)。在问题中,文件名是单数,类名是拼写错误:

in app\Controller\CarrierController.php
                  ^^^^^^^
class CarriesController
      ^^^^^^^

CakePHP 不会在错误命名的文件中找到类,也不会使用位于正确位置但命名错误的类 =)。

关于php - 在非对象 app\Controller\CarriesController.php 第 5 行调用成员函数 create(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22167019/

相关文章:

php - session ,PHP 不完整类

php - 将提交按钮的格式应用于 CakePHP 中的普通按钮

javascript - HTML 页面中的无效字符

具有强大就地编辑功能的 PHP CMS?

php - 使用 sendgrid 和 codeigniter 向多个收件人发送邮件

php - CakePHP - 选择性 SSL

mysql - CakePHP/MySQL 获取松散关联的数据

php - CakePHP 3 - 更改密码

php - 对整数调用成员函数 follow()

php - 向查询添加第二个更新的格式