Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Reference Common Directory files

    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\':

    PHP Code:
    // 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' dirnameDIR_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

  • #2
    New Coder
    Join Date
    Feb 2010
    Location
    UK, North West
    Posts
    36
    Thanks
    0
    Thanked 5 Times in 5 Posts
    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

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks Shaun

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

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    //------ 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"); 

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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?

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #10
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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).

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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):
    PHP Code:
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #12
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks for the info and advice Fou_Lou, going to get stuck into it now

  • #13
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Guess who is back!

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

    PHP Code:
    <?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:

    PHP Code:
    $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 Code:
    <?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?

  • #14
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Where's this class defined?

    Code:
    Class 'BasePeer' not found

  • #15
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Its located under 'C:\fantasy\dao\build\classes\fantasy\'.

    I have the following vhosts entry:

    Code:
    # 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>


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •