【问题标题】:Cakephp Helper fire Error on certain viewCakephp Helper 在某些视图上触发错误
【发布时间】:2013-02-06 16:54:16
【问题描述】:

我的助手遇到了一些奇怪的事情。 首先,我刚开始使用 cakePHP 和 MVC。 也许我做错了什么,但找不到什么。

对于我的应用程序,我必须使用 Xml 文件来处理我的文本的语言(我知道有很多不同的方式来处理语言,但我需要使用这个)。 所以我创建了一个 Helper(XmlHelper.php,在 View\Helper\Xmlhelper.php 中)

<?php
App::uses('AppHelper', 'View/Helper','Xml');


class XmlHelper extends AppHelper {
    var $xml = array();
    var $name = 'Xml';
    var $filename = '';

    public function getXml($filename, $language, $view) {
         $this->xml = Xml::toArray(Xml::build('Xml/'.$filename.'.xml')); //THE LINE
         $this->xml = $this->xml[$filename][$language][$view];
         $this->filename = $filename;
    }

    public function readXml($tags) {
        $tempXml =  $this->xml;
        foreach ($tags as $tag){
            $tempXml =  $tempXml[$tag];
        }
        return  $tempXml;
    }
}

从我的控制器我得到:

class EventsController extends Controller {
public $helpers = array('Html', 'Form','Xml');
    public $components = array('Session');

在我的大部分观点中,一切都很好,但其他一些只是开火

Error: Class 'Xml' not found File:
C:\wamp\www\cakephp\app\View\Helper\Xmlhelper.php Line: 11

在我看来,我称之为:

<?php $this->Xml->getXml('dico',$ln,'thanks'); ?>
<h1><?php echo $this->Xml->readXml(array('texte'));?></h1>

ln 定义明确。

如果有人能解释我出了什么问题,那将非常感激!

【问题讨论】:

    标签: cakephp helper php


    【解决方案1】:

    问题在于您在内部您的 XmlHelper 中使用的 XML 类。

    基本上你用App:uses();错了,一次只能包含一个类,所以你需要再加一行:

    App::uses('AppHelper', 'View/Helper');
    App::uses('Xml', 'Path/To/Xml.php');
    

    我无法真正帮助您处理 Path/To/Xml.php 位,因为我不知道您将它保存在哪里。如果它是一个外部库,它真的应该在 Vendors 文件夹中。 See here for more info.

    【讨论】:

    • 干得好,我必须使用:App::uses('Xml', 'Utility');非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    • 2017-01-26
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多