How do you organize your back-end file wise?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: How do you organize your back-end file wise?

Post by JAB Creations »

Luke wrote:Tell me, what's the point of building every piece of a project by yourself? What's wrong with using well-tested, tried-and-true code written by better developers than yourself? :?
I thought I was already past that point? I'm stuck at the path issue and this unfamiliar code and indecisive tutorial isn't helping. :|
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: How do you organize your back-end file wise?

Post by josh »

You must create your own bootstrap ( since that really is application specific ). THis is where you set up application wide settings, instantiate the front controller, and dispatch it. For me my bootstrap is just another 'ol object in my system, and index.php instantiates it and calls ->run(). run() calls dispatch() on the front controller. The tutorial covers setting up a minimal procedural bootstrap for most applications. Generally in the bootstrap you would set up auto loading which is probably why you're getting errors. Since its complaining about relative paths that means you also did not set up your include path.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: How do you organize your back-end file wise?

Post by JAB Creations »

josh wrote:Generally in the bootstrap you would set up auto loading which is probably why you're getting errors. Since its complaining about relative paths that means you also did not set up your include path.
I have toyed with all the paths here and nothing seems to work. Again here is the file structure...
http://localhost/zend/
http://localhost/zend/application/
http://localhost/zend/public_html/
http://localhost/zend/Zend/

I haven't seen PHP code like they are using here so a little help would be greatly appreciated, why not just use simple includes?

index.php

Code: Select all

<?php
// public/index.php
//
// Step 1: APPLICATION_PATH is a constant pointing to our
// application/subdirectory. We use this to add our "library" directory
// to the include_path, so that PHP can find our Zend Framework classes.
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application/'));
set_include_path(
    APPLICATION_PATH . '/../library' 
    . PATH_SEPARATOR . get_include_path()
);
 
// Step 2: AUTOLOADER - Set up autoloading.
// This is a nifty trick that allows ZF to load classes automatically so
// that you don't have to litter your code with 'include' or 'require'
// statements.
require_once "../Zend/Loader.php";
Zend_Loader::registerAutoload();
 
// Step 3: REQUIRE APPLICATION BOOTSTRAP: Perform application-specific setup
// This allows you to setup the MVC environment to utilize. Later you 
// can re-use this file for testing your applications.
// The try-catch block below demonstrates how to handle bootstrap 
// exceptions. In this application, if defined a different 
// APPLICATION_ENVIRONMENT other than 'production', we will output the 
// exception and stack trace to the screen to aid in fixing the issue
try {
    require '../application/bootstrap.php';
} catch (Exception $exception) {
    echo '<html><body><center>'
       . 'An exception occured while bootstrapping the application.';
    if (defined('APPLICATION_ENVIRONMENT')
        && APPLICATION_ENVIRONMENT != 'production'
    ) {
        echo '<br /><br />' . $exception->getMessage() . '<br />'
           . '<div align="left">Stack Trace:' 
           . '<pre>' . $exception->getTraceAsString() . '</pre></div>';
    }
    echo '</center></body></html>';
    exit(1);
}
 
 
// Step 4: DISPATCH:  Dispatch the request using the front controller.
// The front controller is a singleton, and should be setup by now. We 
// will grab an instance and call dispatch() on it, which dispatches the
// current request.
Zend_Controller_Front::getInstance()->dispatch();
?>
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: How do you organize your back-end file wise?

Post by josh »

Maybe the include path is setup wrong? Auto loading prevents littering your scripts with needless require statements. You can still require those files manually if you wanted, and it would work, but I'd sort out the include_path problem.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: How do you organize your back-end file wise?

Post by papa »

Chris Corbyn wrote:You're a fruit retailer. You've got a database of sales that shows the numbers of each type of fruit in each transaction, along with the sale amounts. Now let's say the task here to is create a simple page that gives a table, showing the combined sale amounts for each type of fruit in any given month. The user should be able to change the month and the year in order to see the sales for that period.

I think this makes for a very simple model, an incredibly simple controller, and a very basic view. Should we do it?

I can see how people will get carried away applying other patterns here... keep it to the basics. We can work with superglobals directly etc for now.
I would really appreciate a walk through with some basic examples just to get a better understanding. I watched the movies that was provided earlier in this thread about setting up Zend etc and understood the concept and was really impressed. Have no previous experience of frameworks but it really caught my attention. :)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: How do you organize your back-end file wise?

Post by josh »

Best way is to dive in and start using it.

Check out the reaper's blog post ( not going to attempt spelling the first part of his handle ): http://blog.astrumfutura.com/archives/3 ... cture.html
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: How do you organize your back-end file wise?

Post by papa »

josh wrote:Best way is to dive in and start using it.

Check out the reaper's blog post ( not going to attempt spelling the first part of his handle ): http://blog.astrumfutura.com/archives/3 ... cture.html
True. (very nice link, thanks!)

I felt that I might need to read up on MVC and learn how that works. Any tips regarding that ?

I've read a couple of discussions here on the forum about have views etc, but am not that familiar with that kind of design.

ot:
Have you changed your name ? :p
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: How do you organize your back-end file wise?

Post by josh »

Yeah I had my name changed from jshpro2. Like I said its one of those things, a sailor does not automatically get his sea legs, you have to plow thru a certain amount of uncomfortableness first. Best bet is to read all the info you can source ( what is coupling? What is cohesion? What is layered software? What are packages? What is a domain model? what are unit tests? What is presentation logic? what is business logic? What is refactoring? What are design patterns? ). As you come across terms you don't know, don't just keep reading, keep a to-do list of things to learn about, etc... If you really want to understand the stuff purchase POEAA
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: How do you organize your back-end file wise?

Post by papa »

Kewl thanks man.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: How do you organize your back-end file wise?

Post by JAB Creations »

:offtopic:
I haven't been able to touch a shred of code for two or three days now though this is still a high priority. Will be building a book shelf so I can actually stack stuff in my room...then I'll have room in my room. :)

Yeah...I keep looking for examples of why and I can't find anything. I'll resume messing with Zend tomorrow though if it takes more then an hour (and no replies) and I still can't get the includes to work I'll just look at other frameworks others have suggested. I did get the chance to look up the difference between includes and require_once which was an interesting read so I now thankfully have that in mind from this point onwards. :)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: How do you organize your back-end file wise?

Post by Eran »

The include / require is pretty basic stuff and has nothing to do with ZF or any other framework.
Try this:

Code: Select all

 set_include_path(
     dirname( dirname(__FILE__) ) . '/library'
     . PATH_SEPARATOR . get_include_path()
); 
Your application structure should be like this (and not like the one you posted):

Code: Select all

 /projectname/
/projectname/application/
/projectname/public_html/
/projectname/library
/projectname/library/Zend 
replace projectname with the name of the project you are developing (maybe helloworld?), unless it is actually called zend..
Before you were adding to the include path a non-existing directory, yet somehow you pointed the inclusion of the Zend_Loader to the correct directory (require_once "../Zend/Loader.php";)
If you were more consistent and tried to figure out why it wasn't working you would have solved it easily..
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do you organize your back-end file wise?

Post by Christopher »

It may be that his URLs are http://localhost/zend/public_html/ and not http://localhost/. Zend requires you to do a couple of things to get it to work in a sub directory. I don't recall it being very well documented.
(#10850)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: How do you organize your back-end file wise?

Post by Eran »

his URLs are definitely /zend/ etc
it should the project name instead...

This is how I have all of my projects by the way on my localhost. none are at the document root. In either case, I gave a suggestion for a simple fix
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: How do you organize your back-end file wise?

Post by John Cartwright »

arborint wrote:It may be that his URLs are http://localhost/zend/public_html/ and not http://localhost/. Zend requires you to do a couple of things to get it to work in a sub directory. I don't recall it being very well documented.
If memory recalls, it was a simple matter of setting/adjusting the RewriteBase directive.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: How do you organize your back-end file wise?

Post by josh »

If my memory recalls you have to do nothing, the request object automatically detects base URLs
10.4.2.2. Base Url and Subdirectories

Zend_Controller_Request_Http allows Zend_Controller_Router_Rewrite to be used in subdirectories. Zend_Controller_Request_Http will attempt to automatically detect your base URL and set it accordingly.

For example, if you keep your index.php in a webserver subdirectory named /projects/myapp/index.php, base URL (rewrite base) should be set to /projects/myapp. This string will then be stripped from the beginning of the path before calculating any route matches. This frees one from the necessity of prepending it to any of your routes. A route of 'user/:username' will match URIs like http://localhost/projects/myapp/user/martel and http://example.com/user/martel.
[Note] URL detection is case sensitive

Automatic base URL detection is case sensitive, so make sure your URL will match a subdirectory name in a filesystem (even on Windows machines). If it doesn't, an exception will be raised.

Should base URL be detected incorrectly you can override it with your own base path with the help of the setBaseUrl() method of either the Zend_Controller_Request_Http class, or the Zend_Controller_Front class. The easiest method is to set it in Zend_Controller_Front, which will proxy it into the request object. Example usage to set a custom base URL:
http://framework.zend.com/manual/en/zen ... quest.html
Post Reply