1

我在使用 Kohana 3.1 时遇到问题。我添加了旧银行 kohana-email 模块,但结果是这样的错误:

ErrorException [致命错误]:找不到类“电子邮件”

我的应用程序 bootstrap.php 文件是这样的:

Kohana::modules(array(
    'user'      => MODPATH.'user',   // Useradmin module
    'auth'      => MODPATH.'auth',   // Basic authentication
    // 'cache'      => MODPATH.'cache',      // Caching with multiple backends
    // 'codebench'  => MODPATH.'codebench',  // Benchmarking tool
    'database'  => MODPATH.'database',   // Database access
    // 'image'      => MODPATH.'image',      // Image manipulation
    'orm'           => MODPATH.'orm',        // Object Relationship Mapping
    'kohana-email'  => MODPATH.'kohana-email',   // Kohana email module
    //'email'       => MODPATH.'email',     // Email module
    //'mailer'      => MODPATH.'mailer',        // Mailer module
    'pagination'    => MODPATH.'pagination', // Pagination module
    'testmod'   => MODPATH.'testmod',
    // 'unittest'   => MODPATH.'unittest',   // Unit testing
    // 'userguide'  => MODPATH.'userguide',  // User guide and API documentation
    ));

如您所见,我尝试使用另一个电子邮件模块(邮件模块和 shadowhand 的电子邮件模块),结果相同。

考虑到错误消息,我只使用这样的 init.php 文件创建了一个模块(名为 testmod):

<?php
  die('It works');
?>

然后,在引导程序中添加 testmod 模块,我得到“它可以工作”。

那么,如果其他模块(如 orm、auth、user)工作正常,为什么 kohana-email、emailer 和 mailer 不能工作?

编辑:我必须扩展我的解释:

kohana-email 模块位于 中MODPATH.'kohana-email',因为这样做echo MODPATH;我可以看到正确的模块位置。

我的模块文件树是这样的:

modules (as echo MODPATH says)
  |
  +-- user     (files from user module, this module works right)
  |
  +-- auth     (files from auth module, this module works right)
  |
  +-- testmod     (init.php file from testmod, this module works right)
  |
  +-- kohana-email
  !     |
  :     +-- classes
  :     |     |
  :     |     +-- email.php    <--- The Email class is here!
  :     |
  :     +-- config
  :     |     |
  :     |     +-- email.php
  :     |
  :     +-- vendor
  ·           |
  ·           +-- swift
                    !
                    :     (files from swift)
                    ·

是的,我Email::connect();在同一个 bootstrap.php 中,在该Kohana::modules行之后进行了探测,并且在这里引发了 ErrorException。而且,是的,我用 shadowhand 电子邮件模块探测它,但我得到了同样的错误。

所以,我再问一个问题:

为什么 kohana-email(以及电子邮件和邮件程序)模块不起作用?或者,为什么 kohana 找不到 Email 类?

4

2 回答 2

1

问题是模块目录权限,您可以在此处看到:

echo Debug::vars('What does this mean? Look at '.__FILE__.' line '.__LINE__,
/**
* PROTIP: Wrapping several variables in an array() prevents tailing
* commas "," causing exceptions.
*
* Each step below was added after the last step returned the expected result.
*/
array(
  // The path to the module
  $p = MODPATH.'kohana-email',
  // should be a directory
  is_dir($p),
  // The path to "classes/"
  $c = $p.DIRECTORY_SEPARATOR.'classes',
  // should also be directory
  is_dir($c),
  // This doesn't seem right... the last call said it wasn't a directory
  shell_exec('ls -al '.escapeshellarg($c)),
  // That failed too? Wait a second...
  shell_exec('ls -al '.escapeshellarg(MODPATH)),
  // It looks like the the module directory is not readable!
  is_readable($p),
  is_readable($c),
  // Both returned FALSE! We need to correct the permissions!
  // I ran the following commands in my console the project root:
  // $ find modules/ -type d -exec chmod 0755 {} \;
  // $ find modules/ -type f -exec chmod a+r {} \;
  // All permissions should be fixed now, all previous debugging was
  // returning the proper values, so attempt to load the class
  class_exists('Email'),
  // Hooray!
  Email::connect(),
  )
);

感谢影手。

于 2011-04-06T13:11:45.397 回答
0

我有一个类似的问题。在我的本地主机(OS Windows)上一切正常,但在服务器(Ubuntu)上我已经收到此错误。我刚刚重命名email.phpEmail.phpin modules/email/classes,一切正常。

于 2013-07-05T14:58:27.797 回答