Hello,
On 12/14/2002 07:38 PM, Jason Hines wrote:
> Is there an example available anywhere that demonstrates how the
> generated data classes / factory class should be interfaced within an
> external PHP script? The documentation does not illustrate this.
Yes, you are right, the documentation needs to be improved on this
aspect. I will try to provide something in that direction soon.
> My first inclination would be something like:
>
> include("cms.php");
> include("article.php");
Yes...
> $article = new articleclass();
No, objects should be created by the factory class, calling functions
defined the component XML definition. These functions can be to create a
new object from scratch or to create objects retrieved from the
persistence contains which in the current Metastorage version can only
be a relational database.
I will provide a better example later, but a possible script to create
and persist an article object would look like this:
require("cms.php");
require("article.php");
$factory=&new cmsclass;
$factory->connection="mysql://localhost/cms";
$factory->includepath="metabase/relative/path/to/script";
if($factory->initialize())
{
$article=$factory->createarticle();
if($article!=null)
{
$article->title="My first article";
$article->persistarticle();
}
$factory->finalize();
}
if(strlen($factory->error))
echo "Error: ".$factory->error;
--
Regards,
Manuel Lemos