CakePHP找不到Controller

时间:2016-09-20 05:28:02

标签: php cakephp-3.0

我已经在CakePHP上创建了一个项目,但是当我从视图中发送表单数据时,它显示了Missing Controller。我也为此创建了控制器。这是守则。

Index.ctp           

<title>Student</title>
<center><h1>REGISTRATION FORM</h1></Center>
<?php 

echo $this->Form->create(null, ['url' => ['controller' => 'Controller', 'action' => 'save']])
?>
    <table class="table">
        <tr>
            <td>Fname<input type="text" name="fname" ></td>
        </tr>
                <tr>
            <td>Lname<input type="text" name="lname" ></td>
        </tr>
        <tr>
            <td>Email<input type="text" name="email" ></td>
        </tr>
        <tr>
            <td>Password<input type="text" name="password" ></td>
        </tr>
                <tr>
            <td>Gender<input type="text" name="gender" ></td>
        </tr>
        <tr>
            <td>About<input type="text" name="about" ></td>
        </tr>
            <td><input type="submit" class="btn btn-primary" value="Save"></td>
        </tr>
</table>
<center><h1>DISPLAY DATA</h1></Center>
<?php echo $this->Form->end();?>
<table>
    <thead>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Email</th>
            <th>Password</th>
            <th>Gender</th>
            <th>About</th>
            <th>Edit</th>
            <th>Delete</th>
        </tr>
    </thead>
    <tbody>
        <?php 
            foreach($data as $row)
            {
                ?>
                    <tr>
                        <td><?= $row->fname ?></td>
                        <td><?= $row->lname ?></td>
                        <td><?= $row->email ?></td>
                        <td><?= $row->password ?></td>
                        <td><?= $row->gender ?></td>
                        <td><?= $row->about ?></td>
                        <td><?= $this->Html->link('Edit',array('controller'=>'Stud','action'=>'edit'.'/'.$row->id))?>|
                        <?= $this->Html->link('Delete',array('controller'=>'Stud','action'=>'delete'.'/'.$row->id))?>
                        </td>
                    </tr>
                <?php 
            }
        ?>

    </tbody>
</table>

StudController.php

<?php
namespace App\Controller;
use Cake\ORM\TableRegistry;

use App\Controller\AppController;

class StudController extends AppController
{


    public function index()
    {
        $student = TableRegistry::get('amit');
        $query = $student->find();
        $this->set(array('data' => $query));        
        $this->set('tbstudent', $this->paginate($query));
        $this->render('index');

    }

    public function delete($id)
    {

      $student = TableRegistry::get('amit');
        $query = $student->query();
        $query->delete()
        ->where(['id' => $id])
        ->execute();
        if($query){
            $this->Flash->error(__('Delete Successfully.'));
            $this->redirect(['controller'=>'student','action' => 'index']);
                }
    }

    public function update()
    {
      $student = TableRegistry::get('tbstudent');
        $studentname = $this->request->data('studentname');
        $phone = $this->request->data('phone');
        $id  =  $this->request->data('id');

    $query = $student->query();
        $query->update()
            ->set(['studentname' => $studentname,
                   'phone'       => $phone])
            ->where(['id' => $id])
            ->execute();
        if($query){
            $this->Flash->success('This Information have been update successfully.');
            $this->redirect(['controller'=>'student','action' => 'index']);
        }
    }

    public function edit($id)
    {
      $student = TableRegistry::get('amit');
        $query = $student->query();
        $r   = $student
        ->find()
        ->where(['id' => $id])
        ->first();
        $this->set(array('row' => $r));
        $this->render('edit');
    }

    public function save()
    {
      $student = TableRegistry::get('amit');          

        $fname=$this->request->data('fname');
        $lname=$this->request->data('lname');
        $email=$this->request->data('email');
        $password=$this->request->data('password');
        $gender=$this->request->data('gender');
        $about=$this->request->data('about');



       $query = $student->query();
       $query->INSERT(['fname','lname','email','password','gender','about'])
            ->VALUES([
                'fname'=>$fname, 'lname'=>$lname, 'email'=>$email, 'password'=>$password, 'gender'=>$gender,'about'=>$about
            ])->execute();

        if($query){
                $this->Flash->success('This Information student have been save successfully.');
                $this->redirect(['controller'=>'student','action' => 'index']);
                }
        else
            echo "Unsuccessful";
    }
}

    Please help, My project is stuck because of this

enter image description here

1 个答案:

答案 0 :(得分:1)

echo $this->Form->create(null, ['url' => ['controller' => 'Controller', 'action' => 'save']])

将此更改为

echo $this->Form->create(null, ['url' => ['controller' => 'Stud', 'action' => 'save']])