douyingbei1458 2015-09-21 06:29
浏览 23
已采纳

安装后CakePHP警告和通知

After installing CakePHP successfully, on first time running, I'm getting these warnings at the bottom. How can I fix this.

Warning (2): Missing argument 1 for View::element(), called in /Users/michaelanywar/Sites/cakephp/app/View/Layouts/default.ctp on line 61 and defined [CORE/Cake/View/View.php, line 398]

Notice (8): Undefined variable: name [CORE/Cake/View/View.php, line 416]

Notice (8): Undefined variable: name [CORE/Cake/View/View.php, line 422]

Notice (1024): Element Not Found: Elements/.ctp [CORE/Cake/View/View.php, line 425]

My View/view.php lines from 398 to 427 look like this:

    public function element($name, $data = array(), $options = array()) {
    $file = $plugin = null;

    if (isset($options['plugin'])) {
        $name = Inflector::camelize($options['plugin']) . '.' . $name;
    }

    if (!isset($options['callbacks'])) {
        $options['callbacks'] = false;
    }

    if (isset($options['cache'])) {
        $contents = $this->_elementCache($name, $data, $options);
        if ($contents !== false) {
            return $contents;
        }
    }

    $file = $this->_getElementFilename($name);
    if ($file) {
        return $this->_renderElement($file, $data, $options);
    }

    if (empty($options['ignoreMissing'])) {
    list ($plugin, $name) = pluginSplit($name, true);
        $name = str_replace('/', DS, $name);
        $file = $plugin . 'Elements' . DS . $name . $this->ext;
        trigger_error(__d('cake_dev', 'Element Not Found: %s', $file), E_USER_NOTICE);
    }
}
  • 写回答

2条回答 默认 最新

  • dongmeiba6151 2015-09-21 08:21
    关注

    If you look at your first warning/error message it should be clear what the issue is: "Warning (2): Missing argument 1 for View::element()".

    Look on line 61 of your default layout View template (/app/View/Layouts/default.ctp). You obviously have a call to $this->element() that isn't passing a template name (hence Cake is looking for "Elements/.ctp").

    Make sure you pass a template name to the element() method or remove it from your template. For example, if you want to include the template "View/Elements/site_header.ctp":-

    echo $this->element('site_header');
    

    The template just needs to exist in the 'View/Elements' folder. You don't need to pass the '.ctp' extension to the element() method, Cake assumes this.

    Make sure you've read the docs on Elements.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程