Welcome Guest, Not a member yet? Register   Sign In
Sparks Not Loading
#1

[eluser]mrbinky3000[/eluser]
Hello. Sorry if this is the wrong place to ask for help with CI sparks, but their is no forum link on their website (that I can find).

So, I followed the CI tutorial to create my own spark. I decided to "Spark-i-fy" Google's ReCaptcha code. I ran it through the spark-sdk tests, I uploaded it, people have downloaded it, all seemed fine.

I can't for the life of me get CI 2.0.2 to load the Recaptcha.php file in my sparks/recaptcha/1.11.0/libraries folder. I added some debugging code and it seems like the MY_Loader.php file can find the "libraries" folder for my spark, but won't call Recaptcha.php. I put a die("I made it here") line in the Recaptcha.php __controller() method. It's never called.

When I try to call the method recaptcha_get_html() in Recaptcha.php, I get
Fatal error: Call to a member function recaptcha_get_html() on a non-object

However, example_sparks->helloWorld() works just fine (from the sparks tutorial)

I've seen some bugs about CI's loader, config files, and stuff. Anybody have any ideas?
#2

[eluser]mrbinky3000[/eluser]
Well, I got it to load only by placing a file called autoload.php in the sparks config directory. This file autoloads the recaptcha class and it works.

From the sparks website:
Quote:Note: Autoloading components of your spark is optional, but we do it here to make this tutorial more simple. Generally, you should only autoload what you need to maintain the overall speediness of CodeIgniter.

Doesn't seem like it's optional. In fact, it seems like its required.

Sparks or CI has a problem with their load methods. $this->load->sparks('recaptcha'); doesn't seem to work, but autoloading does.

Investigating more.

Anyone had a problem like this before me?
#3

[eluser]mrbinky3000[/eluser]
So, are we only allowed to Autoload sparks? Seems like $this->load->sparks('.....'); doesn't work. Anyone had a similar problem?
#4

[eluser]bubbafoley[/eluser]
try

Code:
$this->load->spark('...');
#5

[eluser]mrbinky3000[/eluser]
Sorry, I made a type-o in my post, but the code is correct. I am using $this->load->spark() in the code.
#6

[eluser]bubbafoley[/eluser]
hmmm are you getting any errors? I've been using sparks for a while and it works fine but I do the manual installation so I can share sparks across applications.
#7

[eluser]mrbinky3000[/eluser]
No errors. The file would find the sparks folder and then never load the class in my spark's libraries folder.

The example spark has an autoload.php file in it's config folder (see the demo on sparks site). It seems that file needs to be there in order for application/core/MY_loader to load any classes in that spark's "libraries" folder. Helpers, Views, they all load fine, but the class is never initialized and assigned to $this->... unless your spark has that autoload.php file.

I assume "manual install" means you copy the spark files to their proper places in the system/application folder.

It still feels like a bug in the MY_loader, but I guess I'm wrong. The documentation is a little misleading.
#8

[eluser]bubbafoley[/eluser]
Ah ok. Yeah looking at the MY_Loader code you have to have autoload.php in there otherwise it just adds the spark path to the package paths so you can load stuff out of the spark folder. The docs don't make this clear since they never give an example of how to do it without autoloading.

MY_Loader:Confusedpark()
Code:
/**
     * 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;
    }

So you would have to do

Code:
$this->load->spark('recaptcha/1.11.0');
$this->load->library('recaptcha');

or this should work too:

Code:
$this->load->spark('recaptcha/1.11.0', array('library' => 'recaptcha'));

I actually didn't mean manual install. I did the normal install where you download the sparks package files instead of the php curl one line install. I put the spark manager in /usr/local/bin/ and the spark manager lib files and sparks folder in /usr/local/lib/spark/. Then i set SPARKPATH in my index.php to /usr/local/lib/spark/sparks/. This way I can use the same sparks source files and use the spark manager systemwide. Instead of `php tools/spark` from the FCPATH it's just `spark` anywhere. I think I had to tweak the paths in the spark lib files, though.

Code:
bubbafoley:~$ spark list
cli (2.0.0)
curl (1.2.0)
ion_auth (1.4.0)
mongodb (4.0.1)
redis (0.2.0)
spark-sdk (0.0.3)
tags (1.4.0)
template (1.8.0)




Theme © iAndrew 2016 - Forum software by © MyBB