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

Malcolm
  • 289
  • 2
  • 9

2 Answers2

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();
    }
}
Malcolm
  • 289
  • 2
  • 9
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();
    }
}
Ameer Hamza
  • 108
  • 13
  • 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 – Malcolm Mar 25 '15 at 17:06
  • because use statement always placed on the start on php file. – Ameer Hamza Mar 25 '15 at 17:14
  • This won't work either u used "use Parse\ParseObject;" in a function this causes an error too – Malcolm Mar 25 '15 at 17:33
  • 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 – Malcolm Mar 27 '15 at 09:08