【问题标题】:Controller in cakephp 3 not runningcakephp 3 中的控制器未运行
【发布时间】:2022-01-03 10:36:46
【问题描述】:

在 Cakephp 3 中,我在运行代码时创建了一个控制器“TestController”,然后它显示发生了内部错误

TestController.php

<?php 

/**
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link      http://cakephp.org CakePHP(tm) Project
 * @since     0.2.9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

namespace App\Controller;

use App\Controller\AppController; // HAVE TO USE App\Controller\AppController
// use Cake\Event\Event;

class TestController extends AppController
{
    public function index()
    {
        echo "hii";
        // if ($this->Auth->identify()) {
        //     // $this->redirect('uploads/users/'.$_REQUEST['file'])
        //     $this->redirect($_REQUEST['file'])
        // };
        //     // else $this->redirect('AdminUsers/login');
        // else {
        //     http_response_code(404);
        // }
    }
}

但我无法得到它是显示 = 你好 错误 发生了一个内部的错误 错误:发生内部错误。

返回

【问题讨论】:

  • 查看 ./logs/error.log 并在您的问题中粘贴错误
  • 太长了怎么粘贴到这里。
  • 仅复制与您的控制器相关的最新错误消息
  • 2021-11-25 12:44:28 错误:[Cake\View\Exception\MissingTemplateException] 模板文件“Test\index.ctp”丢失。请求网址:/Test
  • 在开发过程中,您应该启用调试模式,然后您将在浏览器中获得更多有用的错误消息,而不必总是查看日志。

标签: cakephp cakephp-3.0


【解决方案1】:

src/Template/Test/index.ctp中添加一个模板文件并添加一些HTML。

您不能在控制器内回显。 CakePHP 将变量发送到视图,您可以在那里访问它:

// in your controller do this:
class TestController extends AppController
   public function index() {
     $message = "Hii";
     $this->set(compact('message'));
   }
}

您的模板文件src/Template/Test/index.ctp 应如下所示:


<?php
 echo $message;
?> 

【讨论】:

  • 谢谢,但仍然没有运行我的视图是` "/>` 我的控制器是$auth_user = $_GET['file']; $auth_user = $_GET['file']; $this&gt;set(compact('auth_user'));
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多