3

I'm trying to get parse to work with codeIgniter's function but it seems that in functions i have to type use quotes whenever i use the use operator

This is what I am suppose to use:

require 'vendor/autoload.php';

use Parse\ParseClient;

ParseClient::initialize('secret', 'secret', 'secret');

use Parse\ParseObject;

$testObject = ParseObject::create("TestObject");
$testObject->set("foo", "bar");
$testObject->save();

I tested and it works perfectly without codeIgniter class and functions.

Problem occurs here when i try to put it in a class

<?php
class MY_Composer 
{
    function __construct() 
    {
        require './vendor/autoload.php';
        use Parse\ParseClient;
        ParseClient::initialize('secret', 'secret', 'secret');

        use Parse\ParseObject;
        $testObject = ParseObject::create("TestObject");
        $testObject->set("foo", "bar");
        $testObject->save();
    }
}

Please help me solve this as I want to use this interesting API

https://www.parse.com/apps/quickstart#parse_data/php

2 Answers 2

2

Thanks but I managed to figure this out myself... put do post any answer you guys think that is better than this :D Happy programming. Cheers

require './vendor/autoload.php';
use Parse\ParseClient;
use Parse\ParseObject;

ParseClient::initialize('secret', 'secret', 'secret');


class MY_Composer 
{
    function __construct() 
    {
        $testObject = ParseObject::create("TestObject");
        $testObject->set("foo", "bar");
        $testObject->save();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

use not works because it always must be placed on the start on php file.

put it on first line after php tag it works properly, like this:

<?php
require './vendor/autoload.php';
use Parse\ParseClient as ParseClient;
use Parse\ParseObject as ParseObject;

class MY_Composer 
{
    function __construct() 
    {
        ParseClient::initialize('secret', 'secret', 'secret');

        $testObject = ParseObject::create("TestObject");
        $testObject->set("foo", "bar");
        $testObject->save();
    }
}

4 Comments

sorry maybe i didn't explain it clearly... the problem was using the use operator... require works fine but when using "use Parse\ParseClient;" in a function there is an error
because use statement always placed on the start on php file.
This won't work either u used "use Parse\ParseObject;" in a function this causes an error too
thanks but i have already figured it out... I have edited my answer... its close to the same as yours... and yours probably works... but I am having lots of troubles with it now... and i don't want anymore so i won't test the code you posted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.