|
|
Rank: Newbie Coder Groups: Member
Joined: 7/13/2007 Posts: 5 Points: 0 Location: Mumbai
|
Hi All,
I was impressed to see the WebORB 2 demos, especially the new console features. Got things setup, and the examples etc work great. Now we want to put a project on it, and I am stuck at how to get PHP work with it.
We have a few PHP classes, a few include files (configuration, db connection info etc). The code works perfect from PHP by itself. I thought I can move the class files to the Services folder and things would work.
Here are a few problems I am facing (if these are WebORB limitations, I think it's not good for any serious development. And if I am missing something, I am all excited to know what!)
* Can we not have constructors for PHP classes? Why can't it automatically invoke them when calling a method? * Why do we have to establish a database connection in every function we need? A DB connection established in one method won't work in another. Isn't there any other way to do this? It's so frustrating otherwise! * Can we use PHP sessions? * Can we keep an include file that does not have class definition in the Services folder? If not, where can we keep it? If this is not possible, what do you guys do for common settings and configuration?
These are just a few things that I have stumbled upon....
I understand that when it's called from Flex, each method call will create a new object.. Why can it not persist? This will save so many troubles!!
TIA.
:Nirav
|
|
 Rank: Administration Groups: Administration
Joined: 8/21/2006 Posts: 675 Points: 1,268 Location: Frisco, TX
|
Hi Nirav, Please see below: * Can we not have constructors for PHP classes? Why can't it automatically invoke them when calling a method? You do not need to declare a constructor. However, if you declare a constructor that accepts some arguments, you also need to declare a constructor without any arguments too. The reason is your service object must instantiated by WebORB so an invocation takes place. WebORB has no way of knowing what constructors you might have and how to invoke them except for the default no-argument one. * Why do we have to establish a database connection in every function we need? A DB connection established in one method won't work in another. Isn't there any other way to do this? It's so frustrating otherwise! You do not have to do it in every function. You can put it into the session in the first invocation and get it from there for the subsequent invocations. * Can we use PHP sessions? yes. * Can we keep an include file that does not have class definition in the Services folder? If not, where can we keep it? If this is not possible, what do you guys do for common settings and configuration? You can put anything you want into the /Services folder. The only caveat is the Service Browser would not work if the /Services folder has a php file without a class definition (the root cause is more of a PHP problem, rather than weborb). This however should not prevent you from being able to invoke your classes from Flex. You can also put those resources outside of the /Services folder and use the appropriate path in the require_once call. As for persisting service object instances, we're adding that functionality and it should be available in the 2.1 release. Thanks, Mark
Mark Piller Midnight Coders, Inc. twitter: midnightcoderblog: blog.themidnightcoders.comwebsite: www.themidnightcoders.com
|
|
Rank: Newbie Coder Groups: Member
Joined: 7/13/2007 Posts: 5 Points: 0 Location: Mumbai
|
Hey Mark,
Good to hear from you! I am trying out the solutions you gave. What's the problem do you have with the Service browser and PHP? If you can give some more details, I can try a hand at it.
:Nirav
|
|
Rank: Newbie Coder Groups: Member
Joined: 7/13/2007 Posts: 5 Points: 0 Location: Mumbai
|
Another issue was with the mysqli functions in PHP. I read on the forums that they are supported, but I couldn't get things to work.. As a matter of fact, I am trying to get my code show up in the Service Browser first, and am getting stuck there. So trying out all the options!
I think it will be worth to write up a small guide once I get this all figured out.. I am almost on the verge of going to HTTP REST way otherwise - passing XML around, rather than bothering with all WebORB configuration ;-)
|
|
 Rank: Administration Groups: Administration
Joined: 8/21/2006 Posts: 675 Points: 1,268 Location: Frisco, TX
|
If you place a PHP file that does not contain a class definition into the /Services folder, Service Browser fails since the PHP reflection completely breaks the processing. There's a getting started guide available in the console (second tab). I am not aware of any issues with the mysqli functions. Cheers, Mark
Mark Piller Midnight Coders, Inc. twitter: midnightcoderblog: blog.themidnightcoders.comwebsite: www.themidnightcoders.com
|
|
Rank: Newbie Coder Groups: Member
Joined: 7/13/2007 Posts: 5 Points: 0 Location: Mumbai
|
I could get the constructor to work. Stored the DB connection identifier in a session and that was available in the actual function called. Am working no the rest of the issues. Still to figure out file includes etc.
Will update here about the progress.
The Getting Started guide is just that :) It explains the Flex part well, but I am sure people will need some more explanation on the PHP setup. Let me complete this setup, and I will write something up.
|
|
Rank: Newbie Coder Groups: Member
Joined: 1/24/2007 Posts: 4 Points: 0 Location: Colombia
|
Mark Piller wrote:
* Why do we have to establish a database connection in every function we need? A DB connection established in one method won't work in another. Isn't there any other way to do this? It's so frustrating otherwise!
You do not have to do it in every function. You can put it into the session in the first invocation and get it from there for the subsequent invocations.
Do you have an example of this Mark?
|
|
Rank: Newbie Coder Groups: Member
Joined: 7/13/2007 Posts: 5 Points: 0 Location: Mumbai
|
So we got it to work finally! Here's some PHP code to illustrate: Code:
class Manager { public function __construct() { /** IMPORTANT ****** If we do not include the prepend file here, the WebORB Service Browser tries to load it, and that will create a problem because of PHP reflection Putting it in the constructor will include the file and make things work. Also, you can not use $GLOBALS to store variables across functions. Storing them in $_SESSION will work though. **/
// The directory this file will get called from is "Consolde" in webroot. // So include path must be relative to that $prepend = "../myproject/includes/prepend.inc.php"; if (is_file($prepend)) // sanity check { include_once($prepend); } } /** * Get a list of all favorite products **/ public function getFavorites() { $query = 'SELECT id, name FROM product_favorites WHERE userId = '.intval($_SESSION['userId']).' ORDER by lastModified DESC'; $_SESSION['mainDB']->Query($query); $result = $_SESSION['mainDB']->Result(); return $result; } } ?>
And an excerpt of my prepend.inc.php: Code: $config["dbhost"] = "localhost"; $config["dbuser"] = "user"; $config["dbpass"] = "pass"; $config["dbname"] = "maindb"; $_SESSION["config"] = $config;
// Include all classes for the application include_once("classes/DB.php");
// Do the DB connection and store it into session // The DB class will use the $_SESSION["config"] values // to connect to the DB $_SESSION["mainDB"] = new DB();
This made it work both from the Service Browser and Flex. It actually also makes it work from the rest of the PHP files I have. Allowing me to test the whole app easily. This is looking good now! Thanks!
|
|
|
Guest |