...

View Full Version : Reference Common Directory files



tom123
03-08-2010, 09:59 PM
Hi

I have the following Projects set up in Eclipse:
- Site_Front_End
- Site_Back_End
- Data_Access_Objects

I'm currently developing the 'Site_Back_End', and have my document root set to C:\My_Site\Site_Back_End\

I currently have a number of constants declared in my index.php file under 'C:\My_Site\Site_Back_End\':


// Separator constants
define( 'DS', '/' );
define( 'PS', PATH_SEPARATOR );

// File path constants
define( 'INDEX_FILE', __FILE__ );

// Doc root constants
define('DIR_ROOT',$_SERVER['DOCUMENT_ROOT']);

// Application root
define( 'DIR_APP' , dirname( DIR_ROOT ) . DS . 'app' . DS );

I was wondering how can I access my files in Data_Access_Objects from this location? I.E. Should I set up some sort of reference in my apache httpd.conf or my php.ini files?

Thanks

Shauny_B
03-09-2010, 10:35 AM
Hello,
You could do what you advised on doing, but you could just contain those file paths on your machine, and include via your code.

You can include paths which are stored not only in www root, but also on the machine. It's a very good concept of having any files which are the data/connection tiers of the site outside of the htdocs folder... For security reasons of course...

Just an suggestion.

Shaun

tom123
03-09-2010, 01:58 PM
Thanks Shaun

Could you provide an exapmle of how you would do this please?

Fou-Lu
03-09-2010, 03:19 PM
This you should not do. In a pure N-Tier approach, you shouldn't allow you're front_end intimate details about you're back_end, and you're back_end should have no intimate details about the DAO. Every layer should be completely unaware of a higher layer than itself. Instead, you should provide it a communication layer between each tier to talk to the next, such as a webservice. In other words, there is no 'common' files per'se, though making a library and having it feed all layers is technically acceptable (also look into using phar for these). I would never suggest that a common configuration file is acceptable.

The purpose of the approach is to allow you to drop the current DAO object and attach to a remote one using the same interface with minor configuration changes. If you're allowing you're layers to talk to each other, than you will never be able to achieve this result. Instead of including working files, you should be opening a connection to that layer instead.

Now, this all said, for optimization purposes you will probably want to create a routing class to determine if the communication is staying onsite or going remote. If staying onsite, you can include the files necessary instead of opening a communication layer. What I would do is create a new communication class, one that handles all soap server and client actions, and has implicit routing to simply include a file instead of opening a soap / rpc / whatever layer. So long as you treat it as a remote connection by using the communicating class, changing to remote is a matter of directing to an external host with the same interface.

That make sense? N-Tier is a completely different paradigm when it comes to web development; you'll need to completely forget what you know about communication between standard PHP webpages, and shift to a completely unlinked communication approach.

tom123
03-09-2010, 10:00 PM
Thanks Fou-Lou

I'm half following you!

Let me briefly explain my setup.

When I say I have a 'DAO' Project, this is where I will be storing all my auto-generated objects (I used Propel to generate these).

So I will need to access these from both my front end and back end sites for adding/editing/deleting records using getters/setters, as well as putting my own custom functions in places.

I'm not sure how I would go about setting up a communication layer to make calls to my DAOs from my front/back end.
Could you possibly provide a very small example or point me to some useful tutorials?

tom123
03-09-2010, 11:15 PM
Hi again Fou-Lou

I've been looking at the COM extension for PHP.

Might it be a good solution to my promlem?

I found the following code, could it be modified to access my objects under the DAO project?
ll:



//------ Create a new COM Object of Crytal Reports 10 ------
$ObjectFactory= new COM("CrystalReports10.ObjectFactory.1");

//------ Create a instance of library Application -------
$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application.10");

Fou-Lu
03-10-2010, 07:13 PM
The COM will not help you when loading PHP files unless you're looking at implementing a dispatcher of some sorts. Best I know, PHP is not capable of doing this. Handy for C++ dll's or executables though.
Look into SOAP. This is the easiest way to deal with this communication layer since every language is capable of sending a plain text format. Some languages make it much easier though, like PHP and java or C# with built in webservice handling.

tom123
04-13-2010, 09:39 PM
Right.....I've spent a good bit of time looking into SOAP.
I've come up with the following:

I have my COM directory with all my DAO's (.class files).
To access these from my Back End and Front End projects I need to create soap server and client objects (maybe create them in separate files and include them in my index.php file where all requests go through?)

The Client Web Service needs to make a http request to the server, my server has to then register all the necessary methods and parameters associated with the class I'm trying to access so that it can generate a wsdl file that tells it how to read the client request. This seems extremely cumbersome, I have over 20 classes each with dozens of methods and coding this would take forever.

I'm getting quite confused reading various articles on the web, I cant seem to find any that are similar to what I'm trying to implement.

Any tips or sites would be greatly appreciated. Has anybody tried implementing something similar to what I'm doing?

Fou-Lu
04-14-2010, 12:34 AM
Ugh, tired of virtual keyboard :(
I'll follow up tomorrow, can you confirm that your .class files are still php (should end with php so as to not show as text), or are they Java class files?

tom123
04-15-2010, 10:33 PM
Hi Fou-Lou

Yes, they are php files. I auto-generated them using the propel framework (I used creole to generate an xml representation of my entires database, I then used this xml file with propel to auto-generate all my classes).

Fou-Lu
04-15-2010, 10:50 PM
Ok good.
As for SOAP, you can attach an actual object to you're SOAP server and serve it out directly. You don't actually need a wsdl if you don't have one; using SOAPServer can generate its own (geez sorry its been awhile so I can't guarentee that this will work):


include_once ('/path/to/a/hander/YourHandlingClass.class.php');

$ss = new SOAPServer(null, array('uri' => 'http://localhost/namespace'));
$ss->setClass('YourHandlingClass');
$ss->handle();

I believe the only difference this will make is that your soap client cannot directly expose the methods, only call them.

Setting up you're client is just about as easy. The idea for this ntier approach would be to allow either a single entry point class to handle everything (such as a Controller represented by YourHandlingClass), or to create a set of accessable classes which can extend the soap server and handle themselves. I personally would look at a single entry point to control anything.

Setting up webservices isn't supposed to be easy, but it provides the best approach for pure n-tier. As soon as you have to directly talk to another layer, the model then becomes a single tier. The only thing that one should have to change for an n-tier application is what its pointing at; altering my SOAPClient address to point at a new location should still provide the same interface against the next layer. Also, front layers should never ever talk to DAO layers. DAO shouldn't be taking care of validation, that is the job of the business layer to process.

tom123
04-20-2010, 09:21 PM
Thanks for the info and advice Fou_Lou, going to get stuck into it now :)

tom123
04-21-2010, 10:52 PM
Guess who is back! :rolleyes:

I have the following server file called index.php set up under the root of my DAO project:


<?php

require 'C:/fantasy/dao/build/classes/fantasy/ChangeTypesPeer.php';

$ss = new SOAPServer(null, array('uri' => 'http://soap/build/classes/fantasy/'));
$ss->setClass('ChangeTypesPeer');
$ss->handle();

?>

I have a file on my back-end which attempts to create a client and connect to the DAO server:


$client = new SoapClient(null,array('location' => 'http://soap/index.php', 'uri' => 'http://soap/index.php'));

echo $client->sayHello();

So as you can see I'm trying to call a test function I set up in my class, which should output some test data to the screen. Here is the class and its functions:



<?php

require 'om/BaseChangeTypesPeer.php';


/**
* Skeleton subclass for performing query and update operations on the 'change_types' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package fantasy
*/
class ChangeTypesPeer extends BaseChangeTypesPeer {


function sayHello() {
$test = "Hello World";
return $test;
}

} // ChangeTypesPeer



I get the following error when running trying to hit the back-end page that creates the client and trys outputting the test data.

Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Class 'BasePeer' not found in C:\fantasy\admin\app\view\members\editMember.php:14 Stack trace: #0 [internal function]: SoapClient->__call('sayHello', Array) #1 C:\fantasy\admin\app\view\members\editMember.php(14): SoapClient->sayHello() #2 C:\fantasy\admin\app\view\common\wrapper.php(6): require('C:\fantasy\admi...') #3 C:\fantasy\admin\app\index.php(40): require('C:\fantasy\admi...') #4 {main} thrown in C:\fantasy\admin\app\view\members\editMember.php on line 14

Any ideas where I'm going wrong?

MattF
04-21-2010, 11:05 PM
Where's this class defined?



Class 'BasePeer' not found

tom123
04-21-2010, 11:15 PM
Its located under 'C:\fantasy\dao\build\classes\fantasy\'.

I have the following vhosts entry:


# This is the configuration for fantasyFootball Web Service
<VirtualHost *:80>
DocumentRoot "C:\fantasy\dao"
ServerName soap
DirectoryIndex index.php index.html
<Directory "C:\fantasy\dao">
AllowOverride All
Allow from all
</Directory>

</VirtualHost>

tom123
04-21-2010, 11:30 PM
Apologies Matt....read the question wrong. I cant find it anywhere under that location i gave you. Thats where all my class files were generated to when I used Propel. Im guessing BasePeer sits under the internal propel file generation application classes. Hmmmm maybe this could get messy due to all the require files,etc?

Fou-Lu
04-21-2010, 11:37 PM
This doesn't actually appear to be a soap issue, although it was triggered as a soap fault, thats simply its reply.
It does appear that the BasePeer is not available at the location required. This appears to be required under the common\wrapper.php file, you'll want to check to ensure that its in the proper path.

tom123
04-24-2010, 03:51 PM
The line the error is occuring on in my wrapper is:


require($mainContentSection);

This is simply including my file editMember.php:


$client = new SoapClient(null,array('location' => 'http://soap/index.php', 'uri' => 'http://soap/index.php'));

echo $client->sayHello();

I done a little searching through the classed changeTypesPeer and BaseChangeTypesPeer which extends it.

ChangeTypesPeer:

<?php

require 'om/BaseChangeTypesPeer.php';


/**
* Skeleton subclass for performing query and update operations on the 'change_types' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package fantasy
*/
class ChangeTypesPeer extends BaseChangeTypesPeer {


function sayHello() {
$test = "Hello World";
return $test;
}

} // ChangeTypesPeer

A part of BaseChangeTypesPeer.php:


<?php

/**
* Base static class for performing query and update operations on the 'change_types' table.
*
*
*
* @package fantasy.om
*/
abstract class BaseChangeTypesPeer {

/** the default database name for this class */
const DATABASE_NAME = 'fantasy';

/** the table name for this class */
const TABLE_NAME = 'change_types';

/** A class that can be returned by this peer. */
const CLASS_DEFAULT = 'fantasy.ChangeTypes';

/** The total number of columns. */
const NUM_COLUMNS = 2;

/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;

/** the column name for the CHANGETYPEID field */
const CHANGETYPEID = 'change_types.CHANGETYPEID';

/** the column name for the NAME field */
const NAME = 'change_types.NAME';

/**
* An identiy map to hold any loaded instances of ChangeTypes objects.
* This must be public so that other peer classes can access this when hydrating from JOIN
* queries.
* @var array ChangeTypes[]
*/
public static $instances = array();

/**
* The MapBuilder instance for this peer.
* @var MapBuilder
*/
private static $mapBuilder = null;

/**
* holds an array of fieldnames
*
* first dimension keys are the type constants
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('Changetypeid', 'Name', ),
BasePeer::TYPE_STUDLYPHPNAME => array ('changetypeid', 'name', ),
BasePeer::TYPE_COLNAME => array (self::CHANGETYPEID, self::NAME, ),
BasePeer::TYPE_FIELDNAME => array ('changeTypeID', 'name', ),
BasePeer::TYPE_NUM => array (0, 1, )
);


I notice there are references to BasePeer in this class but I cannot find it!
Any ideas?

tom123
04-27-2010, 09:53 PM
Ok......Crisis averted!

Major schoolboy error on my part!
I hadnt called some initialization code that is needed for all the classes generted by propel:



set_include_path("C:/fantasy/dao/build/classes" . PATH_SEPARATOR . get_include_path());
require_once 'propel/Propel.php';
Propel::init("C:/fantasy/dao/build/conf/fantasy-conf.php");

It now works :)
Here is link to propel if anyone is interested:
http://www.propelorm.org/wiki/Documentation/1.4/QuickStart

I still have one slight problem but I'm sure only somebody that knows how propel works will be able to help me out.

I have had to comment out the last line at the bottom of all my peer files:


// This is the static code needed to register the MapBuilder for this table with the main Propel class.
//
// NOTE: This static code cannot call methods on the ChangeTypesPeer class, because it is not defined yet.
// If you need to use overridden methods, you can add this code to the bottom of the ChangeTypesPeer class:
//
// Propel::getDatabaseMap(ChangeTypesPeer::DATABASE_NAME)->addTableBuilder(ChangeTypesPeer::TABLE_NAME, ChangeTypesPeer::getMapBuilder());
//
// Doing so will effectively overwrite the registration below.

Propel::getDatabaseMap(BaseChangeTypesPeer::DATABASE_NAME)->addTableBuilder(BaseChangeTypesPeer::TABLE_NAME, BaseChangeTypesPeer::getMapBuilder());




I get the following error is I dont:

Fatal error: Class 'Propel' not found in C:\fantasy\dao\build\classes\fantasy\om\BaseChangeTypesPeer.php on line 686

Does anyone have enough knowledge of propel to know why this is happening?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum