尝试在crud和cakephp之后安装crud-view时未定义的变量和无效的数据类型3.4.11

时间:2017-08-02 21:58:50

标签: cakephp crud cakephp-3.x

我在这里不知所措,希望有人可以提供帮助。我对一般的框架非常陌生,更不用说CakePHP了,但我想我可以在这个问题之后解决这个问题。这似乎是一个非常简单的配置问题,但我不知道我哪里可能出错。对于术语失误道歉,我还在学习。好的,设置:

从带有PHP 7.0.20-1~dotdeb+8.2的干净debian 8系统开始,我按照CakePHP安装说明进行操作。 composer一切顺利。我遵循bookmark tutorial app的教程项目,一切都很好。我安装了FriendsOfCake的crud包,再次,一切都很好,数据库交互很好,crud操作成功。

我还添加了crud-view BootstrapUISearch,并开始按照crud-view说明将其转换为启用了引导程序的ui。这就是问题发生的地方。在src/Controller/AppController.php文件中,我去添加安装说明要添加的代码。在故障排除方面,我一次一行地完成这个过程,看看我是否可以确定问题发生的位置(我知道这不是框架最合乎逻辑的方式,但我老了)。将loadComponent行添加到initialize()函数不会产生任何问题。当我将if语句模糊添加到beforeRender回调时,就会出现问题。这是我的AppController.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 Cake\Controller\Controller;
use Cake\Event\Event;

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @link http://book.cakephp.org/3.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller
{

    /**
     * Initialization hook method.
     *
     * Use this method to add common initialization code like loading components.
     *
     * e.g. `$this->loadComponent('Security');`
     *
     * @return void
     */
    public function initialize()
    {
        parent::initialize();

        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');
        $this->loadComponent('Crud.Crud', [
            'actions' => [
                'Crud.Index',
                'Crud.View',
                'Crud.Add',
                'Crud.Edit',
                'Crud.Delete',
                'Crud.Lookup',
            ],
            'listeners' => [
                // New listeners that need to be added:
                'CrudView.View',
                'Crud.Redirect',
                'Crud.RelatedModels',
                // If you need searching. Generally it's better to load these
                // only in the controller for which you need searching.
                'Crud.Search',
                'CrudView.ViewSearch',
            ]
        ]);

        /*
         * Enable the following components for recommended CakePHP security settings.
         * see http://book.cakephp.org/3.0/en/controllers/components/security.html
         */
        //$this->loadComponent('Security');
        //$this->loadComponent('Csrf');
    }

    /**
     * Before render callback.
     *
     * @param \Cake\Event\Event $event The beforeRender event.
     * @return \Cake\Network\Response|null|void
     */
    public function beforeRender(Event $event)
    {
        if (!array_key_exists('_serialize', $this->viewVars) &&
            in_array($this->response->type(), ['application/json', 'application/xml'])
        ) {
            $this->set('_serialize', true);
        }
    if ($this->viewBuilder()->className() === null) {
            $this->viewBuilder()->className('CrudView\View\CrudView');
        }
    }
}

最后一个if语句会导致破坏,因为它似乎是在crud-view中使用的东西。由于说明有点不清楚,我尝试使用和不使用上面的模糊操作响应中的类型。我认为那不是问题所在。当我进入页面时,我看到了这一点:

Notice (8): Undefined variable: siteTitle [ROOT/vendor/friendsofcake/crud-view/src/Template/Layout/default.ctp, line 24]

Notice (8): Undefined variable: disableSidebar [ROOT/vendor/friendsofcake/crud-view/src/Template/Layout/default.ctp, line 42]

Notice (8): Undefined variable: sidebarNavigation [ROOT/vendor/friendsofcake/crud-view/src/Template/Element/sidebar.ctp, line 2]

    Notice (8): Undefined variable: sidebarNavigation [ROOT/vendor/friendsofcake/crud-view/src/Template/Element/sidebar.ctp, line 10]

    Notice (8): Undefined variable: actionConfig [ROOT/vendor/friendsofcake/crud-view/src/Template/Element/sidebar.ctp, line 12]

    Invalid data type, must be an array or \ArrayAccess instance. InvalidArgumentException
    Documentation API

    If you want to customize this error message, create src/Template/Error/error500.ctp
    toggle vendor stack frames
        ⟩ Cake\Utility\Hash::get ROOT/vendor/friendsofcake/crud-view/src/Template/Element/sidebar.ctp, line 12
        ⟩ include CORE/src/View/View.php, line 1025
        ⟩ Cake\View\View->_evaluate CORE/src/View/View.php, line 986
        ⟩ Cake\View\View->_render CORE/src/View/View.php, line 1372
        ⟩ Cake\View\View->_renderElement CORE/src/View/View.php, line 513
        ⟩ Cake\View\View->element ROOT/vendor/friendsofcake/crud-view/src/Template/Layout/default.ctp, line 51
        ⟩ include CORE/src/View/View.php, line 1025
        ⟩ Cake\View\View->_evaluate CORE/src/View/View.php, line 986
        ⟩ Cake\View\View->_render CORE/src/View/View.php, line 657
        ⟩ Cake\View\View->renderLayout CORE/src/View/View.php, line 615
        ⟩ Cake\View\View->render CORE/src/Controller/Controller.php, line 623
        ⟩ Cake\Controller\Controller->render CORE/src/Http/ActionDispatcher.php, line 125
        ⟩ Cake\Http\ActionDispatcher->_invoke CORE/src/Http/ActionDispatcher.php, line 93
        ⟩ Cake\Http\ActionDispatcher->dispatch CORE/src/Http/BaseApplication.php, line 78
        ⟩ Cake\Http\BaseApplication->__invoke CORE/src/Http/Runner.php, line 65
        ⟩ Cake\Http\Runner->__invoke CORE/src/Routing/Middleware/RoutingMiddleware.php, line 59
        ⟩ Cake\Routing\Middleware\RoutingMiddleware->__invoke CORE/src/Http/Runner.php, line 65
        ⟩ Cake\Http\Runner->__invoke CORE/src/Routing/Middleware/AssetMiddleware.php, line 88
        ⟩ Cake\Routing\Middleware\AssetMiddleware->__invoke CORE/src/Http/Runner.php, line 65
        ⟩ Cake\Http\Runner->__invoke CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 92
        ⟩ Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke CORE/src/Http/Runner.php, line 65
        ⟩ Cake\Http\Runner->__invoke CORE/src/Http/Runner.php, line 51
        ⟩ Cake\Http\Runner->run CORE/src/Http/Server.php, line 80
        ⟩ Cake\Http\Server->run ROOT/webroot/index.php, line 37

依此类推。看起来我错过了一些非常非常简单的东西,但是例如在siteTitle变量之后尝试追溯代码会花费我很多时间。我希望有人可以看一眼这个并且去“哦,你没有在这个文件中抛出这个简单的变量”。非常感谢,感谢让我知道这个问题在哪里出错了。

0 个答案:

没有答案