Welcome Guest, Not a member yet? Register   Sign In
$this->load->script('scriptName') broken
#1

[eluser]wan19800[/eluser]
I am been trying to update my codeigniter from 1.6.1 to 1.7 for a while now

however it is keep giving me Call to undefined method CI_Loader:Confusedcript() on every $this->load->script('scriptName'); that I am trying load external script.

does anyone know what I should do to fix the issue?
Does CI 1.6.2 and above does not allow load from script folder anymore?? what should I do??


thanks,
WH
#2

[eluser]carmencito[/eluser]
In 1.7, the script function has been removed.

This lines of codes were removed from the system/libraries/Loader.php

Code:
/**
     * Load Script
     *
     * This function loads the specified include file from the
     * application/scripts/ folder.
     *
     * NOTE:  This feature has been deprecated but it will remain available
     * for legacy users.
     *
     * @access    public
     * @param    array
     * @return    void
     */
    function script($scripts = array())
    {
        if ( ! is_array($scripts))
        {
            $scripts = array($scripts);
        }
    
        foreach ($scripts as $script)
        {    
            $script = strtolower(str_replace(EXT, '', $script));

            if (isset($this->_ci_scripts[$script]))
            {
                continue;
            }
        
            if ( ! file_exists(APPPATH.'scripts/'.$script.EXT))
            {
                show_error('Unable to load the requested script: scripts/'.$script.EXT);
            }
            
            include_once(APPPATH.'scripts/'.$script.EXT);
        }
        
        log_message('debug', 'Scripts loaded: '.implode(', ', $scripts));
    }

You can try to extend the native CodeIgniter Loader library file to use the deprecated script function. Try this.

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Loader extends CI_Loader {

    var $_ci_scripts        = array();

    // --------------------------------------------------------------------
    
    /**
     * Load Script
     *
     * This function loads the specified include file from the
     * application/scripts/ folder.
     *
     * NOTE:  This feature has been deprecated but it will remain available
     * for legacy users.
     *
     * @access    public
     * @param    array
     * @return    void
     */
    function script($scripts = array())
    {
        if ( ! is_array($scripts))
        {
            $scripts = array($scripts);
        }
    
        foreach ($scripts as $script)
        {    
            $script = strtolower(str_replace(EXT, '', $script));

            if (isset($this->_ci_scripts[$script]))
            {
                continue;
            }
        
            if ( ! file_exists(APPPATH.'scripts/'.$script.EXT))
            {
                show_error('Unable to load the requested script: scripts/'.$script.EXT);
            }
            
            include_once(APPPATH.'scripts/'.$script.EXT);
        }
        
        log_message('debug', 'Scripts loaded: '.implode(', ', $scripts));
    }

}

...save the code as MY_Loader.php and place it inside system/application/libraries/ directory. The prefix MY_ depends on whether you change the config value for subclass_prefix in config.php
Code:
$config['subclass_prefix'] = 'MY_';
#3

[eluser]wan19800[/eluser]
Thank you so much carmencito.

after I done what you told me there is still one issue that needed to be resolved

for:
Code:
/*
| -------------------------------------------------------------------
|  Auto-load Scripts
| -------------------------------------------------------------------
| The term "scripts" refers to you own PHP scripts that you've
| placed in the application/scripts/ folder
|
| Prototype:
|
|    $autoload['script'] = array('my_script1', 'my_script2');
*/

$autoload['script'] = array('my_script1', 'my_script2');



how can I autoload from the script folder?


thanks,
WH
#4

[eluser]carmencito[/eluser]
Edit MY_Loader.php and ADD THIS FUNCTION

Code:
/**
     * Autoloader
     *
     * The config/autoload.php file contains an array that permits sub-systems,
     * libraries, plugins, and helpers to be loaded automatically.
     *
     * @access    private
     * @param    array
     * @return    void
     */
    function _ci_autoloader()
    {    
        include_once(APPPATH.'config/autoload'.EXT);
        
        if ( ! isset($autoload))
        {
            return FALSE;
        }
        
        // Load any custom config file
        if (count($autoload['config']) > 0)
        {            
            $CI =& get_instance();
            foreach ($autoload['config'] as $key => $val)
            {
                $CI->config->load($val);
            }
        }        

        // Autoload plugins, helpers and languages
        foreach (array('helper', 'plugin', 'script', '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']))
        {
            $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 scaffolding
            if (in_array('scaffolding', $autoload['libraries']))
            {
                $this->scaffolding();
                $autoload['libraries'] = array_diff($autoload['libraries'], array('scaffolding'));
            }
        
            // Load all other libraries
            foreach ($autoload['libraries'] as $item)
            {
                $this->library($item);
            }
        }        

        // Autoload models
        if (isset($autoload['model']))
        {
            $this->model($autoload['model']);
        }

    }

Change made:

FROM
Code:
// Autoload plugins, helpers and languages
foreach (array('helper', 'plugin', 'language') as $type)

TO
Code:
// Autoload plugins, helpers and languages
foreach (array('helper', 'plugin', 'script', 'language') as $type)


Hope that will do the trick does your $autoload[‘script’] = array(‘my_script1’, ‘my_script2’); now works
#5

[eluser]wan19800[/eluser]
thanks carmencito,

now I can use script folder !! thank you so much for the help



WH
#6

[eluser]carmencito[/eluser]
you are very much welcome wan19800.. :-)




Theme © iAndrew 2016 - Forum software by © MyBB