Php 设置带有火花的codeigniter时出现的问题;活动记录

Php 设置带有火花的codeigniter时出现的问题;活动记录,php,mysql,codeigniter-2,phpactiverecord,Php,Mysql,Codeigniter 2,Phpactiverecord,我在让我的sparks安装与我的codeigniter安装一起使用时遇到问题 以下是我采取的步骤,具体如下: RewriteBase / 我通过PHPCLI转到codeigniter项目文件夹的根目录,使用下面的命令安装sparks php -r "$(curl -fsSL http://getsparks.org/go-sparks)" 我使用下面的spark命令安装了活动记录库 php tools\spark install -v0.0.2 php-activerecord 2a。

我在让我的
sparks
安装与我的
codeigniter
安装一起使用时遇到问题

以下是我采取的步骤,具体如下:

RewriteBase /
  • 我通过
    PHPCLI
    转到
    codeigniter
    项目文件夹的根目录,使用下面的命令安装sparks

    php -r "$(curl -fsSL http://getsparks.org/go-sparks)"
    
  • 我使用下面的spark命令安装了活动记录库

    php tools\spark install -v0.0.2 php-activerecord
    
  • 2a。这个命令给了我以下文件夹结构

    -application
    -sparks
       -php-activerecord
          -0.0.2
             -config
             -variables
             -vendor
    -system
    -tests
    -tools
       -lib
          -spark
             -sparktypes
       -test
    -user_guide
    
    2b。此命令生成一个
    sparks
    文件夹,其中包含构成
    php activerecord
    必要组件的
    php activerecord
    ,该命令使用生成一个
    MY_Loader.php
    文件,如下所示

    <?php  if (! defined('BASEPATH')) exit('No direct script access allowed');
    /**
     * Sparks
     *
     * An open source application development framework for PHP 5.1.6 or newer
     *
     * @package     CodeIgniter
     * @author      CodeIgniter Reactor Dev Team
     * @author      Kenny Katzgrau <katzgrau@gmail.com>
     * @since       CodeIgniter Version 1.0
     * @filesource
     */
    
    /**
     * Loader Class
     *
     * Loads views and files
     *
     * @package     CodeIgniter
     * @subpackage  Libraries
     * @author      CodeIgniter Reactor Dev Team
     * @author      Kenny Katzgrau <katzgrau@gmail.com>
     * @category    Loader
     * @link        http://codeigniter.com/user_guide/libraries/loader.html
     */
    class MY_Loader extends CI_Loader
    {
        /**
         * Keep track of which sparks are loaded. This will come in handy for being
         *  speedy about loading files later.
         *
         * @var array
         */
        var $_ci_loaded_sparks = array();
    
        /**
         * Is this version less than CI 2.1.0? If so, accomodate
         * @bubbafoley's world-destroying change at: http://bit.ly/sIqR7H
         * @var bool
         */
        var $_is_lt_210 = false;
    
        /**
         * Constructor. Define SPARKPATH if it doesn't exist, initialize parent
         */
        function __construct()
        {
            if(!defined('SPARKPATH'))
            {
                define('SPARKPATH', 'sparks/');
            }
    
            $this->_is_lt_210 = (is_callable(array('CI_Loader', 'ci_autoloader'))
                                   || is_callable(array('CI_Loader', '_ci_autoloader')));
    
            parent::__construct();
        }
    
        /**
         * To accomodate CI 2.1.0, we override the initialize() method instead of
         *  the ci_autoloader() method. Once sparks is integrated into CI, we
         *  can avoid the awkward version-specific logic.
         * @return Loader
         */
        function initialize()
        {
            parent::initialize();
    
            if(!$this->_is_lt_210)
            {
                $this->ci_autoloader();
            }
    
            return $this;
        }
    
        /**
         * Load a spark by it's path within the sparks directory defined by
         *  SPARKPATH, such as 'markdown/1.0'
         * @param string $spark The spark path withint he sparks directory
         * @param <type> $autoload An optional array of items to autoload
         *  in the format of:
         *   array (
         *     'helper' => array('somehelper')
         *   )
         * @return <type>
         */
        function spark($spark, $autoload = array())
        {
            if(is_array($spark))
            {
                foreach($spark as $s)
                {
                    $this->spark($s);
                }
            }
    
            $spark = ltrim($spark, '/');
            $spark = rtrim($spark, '/');
    
            $spark_path = SPARKPATH . $spark . '/';
            $parts      = explode('/', $spark);
            $spark_slug = strtolower($parts[0]);
    
            # If we've already loaded this spark, bail
            if(array_key_exists($spark_slug, $this->_ci_loaded_sparks))
            {
                return true;
            }
    
            # Check that it exists. CI Doesn't check package existence by itself
            if(!file_exists($spark_path))
            {
                show_error("Cannot find spark path at $spark_path");
            }
    
            if(count($parts) == 2)
            {
                $this->_ci_loaded_sparks[$spark_slug] = $spark;
            }
    
            $this->add_package_path($spark_path);
    
            foreach($autoload as $type => $read)
            {
                if($type == 'library')
                    $this->library($read);
                elseif($type == 'model')
                    $this->model($read);
                elseif($type == 'config')
                    $this->config($read);
                elseif($type == 'helper')
                    $this->helper($read);
                elseif($type == 'view')
                    $this->view($read);
                else
                    show_error ("Could not autoload object of type '$type' ($read) for spark $spark");
            }
    
            // Looks for a spark's specific autoloader
            $this->ci_autoloader($spark_path);
    
            return true;
        }
    
        /**
         * Pre-CI 2.0.3 method for backward compatility.
         *
         * @param null $basepath
         * @return void
         */
        function _ci_autoloader($basepath = NULL)
        {
            $this->ci_autoloader($basepath);
        }
    
        /**
         * Specific Autoloader (99% ripped from the parent)
         *
         * The config/autoload.php file contains an array that permits sub-systems,
         * libraries, and helpers to be loaded automatically.
         *
         * @param array|null $basepath
         * @return void
         */
        function ci_autoloader($basepath = NULL)
        {
            if($basepath !== NULL)
            {
                $autoload_path = $basepath.'config/autoload'.EXT;
            }
            else
            {
                $autoload_path = APPPATH.'config/autoload'.EXT;
            }
    
            if(! file_exists($autoload_path))
            {
                return FALSE;
            }
    
            include($autoload_path);
    
            if ( ! isset($autoload))
            {
                return FALSE;
            }
    
            if($this->_is_lt_210 || $basepath !== NULL)
            {
                // Autoload packages
                if (isset($autoload['packages']))
                {
                    foreach ($autoload['packages'] as $package_path)
                    {
                        $this->add_package_path($package_path);
                    }
                }
            }
    
            // Autoload sparks
            if (isset($autoload['sparks']))
            {
                foreach ($autoload['sparks'] as $spark)
                {
                    $this->spark($spark);
                }
            }
    
            if($this->_is_lt_210 || $basepath !== NULL)
            {
                if (isset($autoload['config']))
                {
                    // Load any custom config file
                    if (count($autoload['config']) > 0)
                    {
                        $CI =& get_instance();
                        foreach ($autoload['config'] as $key => $val)
                        {
                            $CI->config->load($val);
                        }
                    }
                }
    
                // Autoload helpers and languages
                foreach (array('helper', 'language') as $type)
                {
                    if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
                    {
                        $this->$type($autoload[$type]);
                    }
                }
    
                // A little tweak to remain backward compatible
                // The $autoload['core'] item was deprecated
                if ( ! isset($autoload['libraries']) AND isset($autoload['core']))
                {
                    $autoload['libraries'] = $autoload['core'];
                }
    
                // Load libraries
                if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
                {
                    // Load the database driver.
                    if (in_array('database', $autoload['libraries']))
                    {
                        $this->database();
                        $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
                    }
    
                    // Load all other libraries
                    foreach ($autoload['libraries'] as $item)
                    {
                        $this->library($item);
                    }
                }
    
                // Autoload models
                if (isset($autoload['model']))
                {
                    $this->model($autoload['model']);
                }
            }
        }
    }
    
    当我运行codeigniter站点时,我得到以下错误

    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Use of undefined constant EXT - assumed 'EXT'
    
    Filename: core/MY_Loader.php
    
    Line Number: 174
    
    Backtrace:
    
    File: C:\xampp\htdocs\orm\application\core\MY_Loader.php
    Line: 174
    Function: _exception_handler
    
    File: C:\xampp\htdocs\orm\application\core\MY_Loader.php
    Line: 154
    Function: ci_autoloader
    
    File: C:\xampp\htdocs\orm\application\core\MY_Loader.php
    Line: 67
    Function: initialize
    
    File: C:\xampp\htdocs\orm\index.php
    Line: 274
    Function: require_once
    

    我很好奇是什么导致了这个错误?如果我缺少任何其他配置,或者我犯了错误,请告诉我。

    您的根
    index.php
    文件中定义了
    EXT

    // The PHP file extension
    // this global constant is deprecated.
    define('EXT', '.php');
    

    看看它是否还在那里?

    如果常量不在那里,您也可以定义autoload.php而不使用常量。

    我知道这是一篇老文章,但希望这能节省一些时间。。。我有同样的问题,上面的修复不起作用。我最终通过删除RewriteBase修复了htaccess文件中的问题,尽管我不确定这首先为什么会导致这个问题

    刚才注释了这行,如下所示:

    RewriteBase /
    


    我替换了$autoload_path=$basepath.config/autoload.EXT;错误消失了,谢谢,但是我仍然在让orm工作时遇到问题。你是对的,但是我会在application/config/constants.php文件中添加这个定义。
    #RewriteBase /