为什么 Magento 会在“base/default”中查找?我的模板文件?

发布于 2024-11-29 13:06:38 字数 2843 浏览 1 评论 0原文

我使用块类创建了一个非常简单的模块。此块使用自定义模板,该模板调用类方法来确定是否应根据当前时间显示自身(如果支持开放,则显示电话号码)。这在我的本地开发服务器和远程开发服务器上非常有效。它似乎在我们的主站点上运行良好,但今天早上我们开始在主服务器上的日志中看到错误。

错误看起来像这样:

2011-08-11T18:14:49+00:00 ERR (3): 警告: include(/chroot/home/valuepet/valuepetsupplies.com/html/app/design/frontend/base/default/template/ General/banner/orderbyphone.phtml) [function.include]: 无法打开流: 中没有这样的文件或目录/chroot/home/valuepet/valuepetsupplies.com/html/var/ait_rewrite/67b58abff9e6bd7b400bb2fc1903bf2f.php 第 370 行

2011-08-11T18:14:49+00:00 ERR (3): 警告: include() [function.include]: 无法打开 '/chroot/home/valuepet/valuepetsupplies.com/html/app/ design/frontend/base/default/template/general/banner/orderbyphone.phtml' 包含在内(include_path='/chroot/home/valuepet/valuepetsupplies.com/html/app/code/local:/chroot/home/valuepet/valuepetsupplies.com/html/app/code/community:/chroot/home/valuepet/valuepetsupplies .com/html/app/code/core:/chroot/home/valuepet/valuepetsupplies.com/html/lib:.:/usr/share/pear') 在/chroot/home/valuepet/valuepetsupplies.com/html/var/ait_rewrite/67b58abff9e6bd7b400bb2fc1903bf2f.php 第 370 行

我编写的模块在 frontend/base/default 中没有任何内容...仅此而已在我们的自定义主题中。那么为什么它要在 base 中查找文件呢?

我添加了一些日志消息,发现它并不总是在 base 中查找文件...只是偶尔。因此,这表明要么网站中的一个页面错误地调用了该块,要么发生了一些奇怪的事情随机导致了这种情况。

您会从错误消息中注意到,它对某些 PHP 脚本使用了 AIT Rewrite。有人有这方面的经验吗?它附带了另一个 AITOC 扩展,但我找不到任何相关文档。也许这就是问题所在,但我的本地服务器上有相同的扩展,并且不会出现此问题。

有什么想法吗?

=============================

Orderbyphone.php

class VPS_General_Block_Banner_Orderbyphone extends Mage_Core_Block_Template
{
    protected $hours;

    protected function _construct()
    {
        //GMT times for hours of operation
        $this->hours = array('start'    => 15,//15
                                    'end'        => 21);//20

        parent::_construct();
        $this->setTemplate("general/banner/orderbyphone.phtml");
    }

    /**
     * Return true if you should show the OrderByPhone banner, false otherwise
     * @return Boolean
     */
    public function showBanner()
    {
        $GMTHour = (int)date('G');

        if(($GMTHour < $this->hours['start']) || ($GMTHour >= $this->hours['end']))
        {
            return false;
        }

        return true;
    }
}

orderbyphone.pthml

<?php if($this->showBanner()): ?>
    <div><div class='orderbyphone'>Order By Phone 800-VALUEPET (800-825-8373)</div></div>
<?php endif; ?>

通过将以下内容添加到布局中,将此块添加到 CMS 页面更新 XML

<block type="vps_general/banner_orderbyphone" name="orderbyphone">
    <action method="setWidth"><name>400</name></action>
</block>

I created a really simple module with a block class. This block uses a custom template that calls a class method to determine if it should show itself or not based on the current time of day (if support is open, show the phone number). This works great on my local dev server and our remote dev server. It seems to work well on our main site, but we started seeing errors in the log this morning on the main server.

The errors looked like this:

2011-08-11T18:14:49+00:00 ERR (3): Warning: include(/chroot/home/valuepet/valuepetsupplies.com/html/app/design/frontend/base/default/template/general/banner/orderbyphone.phtml) [function.include]: failed to open stream: No such file or directory in /chroot/home/valuepet/valuepetsupplies.com/html/var/ait_rewrite/67b58abff9e6bd7b400bb2fc1903bf2f.php on line 370

2011-08-11T18:14:49+00:00 ERR (3): Warning: include() [function.include]: Failed opening '/chroot/home/valuepet/valuepetsupplies.com/html/app/design/frontend/base/default/template/general/banner/orderbyphone.phtml' for inclusion (include_path='/chroot/home/valuepet/valuepetsupplies.com/html/app/code/local:/chroot/home/valuepet/valuepetsupplies.com/html/app/code/community:/chroot/home/valuepet/valuepetsupplies.com/html/app/code/core:/chroot/home/valuepet/valuepetsupplies.com/html/lib:.:/usr/share/pear') in /chroot/home/valuepet/valuepetsupplies.com/html/var/ait_rewrite/67b58abff9e6bd7b400bb2fc1903bf2f.php on line 370

The module I wrote doesn't have anything in frontend/base/default...it's all in our custom theme. So why was it looking in base for the files?

I added some log messages and found that it doesn't ALWAYS look for the file in base...only occasionally. So that suggests that either one page in the site is calling the block incorrectly or there's something strange going on that causes this randomly.

You'll notice from the error message that it's using AIT Rewrite for some of the PHP scripts. Does anyone have any experience with this? It came with another AITOC extension and I can't find any documentation on it. Perhaps that's the problem, but I have that same extension on my local server and this problem doesn't come up.

Any ideas?

=============================

Orderbyphone.php

class VPS_General_Block_Banner_Orderbyphone extends Mage_Core_Block_Template
{
    protected $hours;

    protected function _construct()
    {
        //GMT times for hours of operation
        $this->hours = array('start'    => 15,//15
                                    'end'        => 21);//20

        parent::_construct();
        $this->setTemplate("general/banner/orderbyphone.phtml");
    }

    /**
     * Return true if you should show the OrderByPhone banner, false otherwise
     * @return Boolean
     */
    public function showBanner()
    {
        $GMTHour = (int)date('G');

        if(($GMTHour < $this->hours['start']) || ($GMTHour >= $this->hours['end']))
        {
            return false;
        }

        return true;
    }
}

orderbyphone.pthml

<?php if($this->showBanner()): ?>
    <div><div class='orderbyphone'>Order By Phone 800-VALUEPET (800-825-8373)</div></div>
<?php endif; ?>

This block is added to a CMS pages by adding the following to the Layout Update XML

<block type="vps_general/banner_orderbyphone" name="orderbyphone">
    <action method="setWidth"><name>400</name></action>
</block>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2024-12-06 13:06:38

考虑到 Magento 的级联方式搜索模板资源,它在 /base/default/ 中找不到资源这一事实并不一定意味着您指定了该路径。

事实上,如果您告诉 Magento 在 /yourpackage/yourtheme/ 路径中加载模板资源,而 Magento 找不到该资源,它将在 /base/default/< 中搜索相同的资源/代码> 路径。

如果即使在 /base/default/ 中也找不到它,它会抛出异常,表示该资源未在 /base/default/中找到/ 不在 /yourpackage/yourtheme/ 路径中。

我不知道是否是这种情况,但也许它可以帮助你一点。
换句话说:您确定您要查找的资源位于 /yourpackage/yourtheme/ 路径中吗?

请注意,Unix/Linux 下文件名区分大小写,因此在 Windows 下找到的内容不一定在 Unix/Linux 下找到。

问候, 亚历山德罗

considering Magento's cascading way of searching for template assets the fact that it doesn't find an asset in /base/default/ doesn't necessarily mean that you specified that path.

In fact if you tell Magento to load a template asset in /yourpackage/yourtheme/ path and Magento doesn't find that asset it will search for the same asset in /base/default/ path.

If it doesn't find it even in /base/default/ it will throw an exception saying that the resource wasn't fount in the /base/default/ not in /yourpackage/yourtheme/ path.

I don't know if this is the case but maybe it can help you a bit.
In other words: are you sure the resource you are looking for is in /yourpackage/yourtheme/ path?

Pay attention to the fact that file names are case sensitive under Unix/Linux so what is found under Windows is not necessarily found under Unix/Linux.

Regards, Alessandro

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文