tomwalder / php-gds

Google Cloud Datastore Library for PHP
Apache License 2.0
164 stars 44 forks source link

Call objects from inside function #29

Closed emilorol closed 9 years ago

emilorol commented 9 years ago

Hi,

Thank you for this amazing code. I am struggling with something and that is use this code from inside a function. So far I have done something like:


// I have here the GAE configuration
include('config.php');

// Here I setup the client, gateway, and store (user_store)
include('gae.php'); 

function XYZ($username, $password) {
  global $user_store;

  $users = $user_store->fetchOne("SELECT * FROM Users WHERE username = @username AND password = @password", ['username' => $username, 'password' => $password]);

  return $users;
}

But I am not getting any results. What am I missing or is this even possible?

tomwalder commented 9 years ago

Hi there,

There is certainly no reason you can't use the code from functions - I do it loads.

BUT i would not recommend using a global as you have done.

If you want, I can throw some code together as an alternative.

Tom

emilorol commented 9 years ago

Hi Tom,

I would appreciated it tremendously as I am still wrapping my head around OOP and now namespaces and injections and everything else is still ahead of me.

Thank you,

Emil

emilorol commented 9 years ago

Have you got any chance to put together some code?

tomwalder commented 9 years ago

Hi Emil,

I've not forgotten you! Been snowed under recently - but i will put a gist together for you ASAP.

Tom

emilorol commented 9 years ago

Thank you Tom.

I have been dreaming of putting together some sort of CMS or expanding the Bolt CMS to use the datastore and I am sure your library will help me in my quest.

tomwalder commented 9 years ago

Hi there,

I've updated the php-gds-demo application to use some OO code, so you should be able to use that for reference

https://github.com/tomwalder/php-gds-demo

https://github.com/tomwalder/php-gds-demo/blob/master/src/GDS/Demo/Repository.php

Good luck!