Page 4 of 6

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

Posted: Sat Feb 07, 2009 10:00 pm
by Chris Corbyn
JAB, your classes should really accept values from the outside for things like "www.jabcreations.net". Having them hard-coded does not make for very re-usable code.

I'd also say, since you're talking about not getting a job because of your inexperience with MySQL, you almost certainly should do as others are saying and start using a framework. I didn't realise you were applying for jobs. Almost no company is likely to employ somebody who always wants to re-invent the wheel. Part of being a programmer is learning to use the right tool for the job. You'll do yourself a big favour and your (potential) employer a big favour by biting the bullet and using other people's code.

Everyone specializes in different things. You don't have to be able to write a framework to build a CMS. The point of a framework is not to do that work for you; it's to give you the foundations to build from. You still have a lot of work to do if you're building a complete web application in ZF.

I'd also be surprised if most employers will be looking to see that you have experience in one of the mainstream PHP frameworks. I've been to quite a lot of interviews and interviewed people myself and I know from experience that being comfortable working with a framework is almost a requirement. Frameworks promote good programming practice at the end of the day.

I'd suggest that you download Zend Framework, stop trying to re-implement things that you don't need to re-implement and actually start building a real application in a framework, adopting design patterns that fit your needs as you do so. This in itself will be much more valuable experience if you're applying for a job than if you know how to build a request router.

What sort of questions do you expect to be asked at a job interview? They're not likely to ask you if you can build a request router. They're also not likely to be interested in your one-dimensional directory layout. They're likely to ask you about problems you've faced and how you've solved them. Things you find the most challenging. Where you might apply particular design patterns. What frameworks you have used. What tools you use in your workflow. Very general questions that I'm guessing you're not equipped to answer if you always avoid making use of the tools available to you. You're an engineer with a great big toolbox, so start using it ;)

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

Posted: Sat Feb 07, 2009 11:33 pm
by josh
No ones asking you to switch. You asked what the benefits of switching would be and we answered you. ( and then argued with the answer ;-) ). As for how does that look? Not that great. You've got business logic directly encoded in the rewrite rule. Here's mine:

<Directory "C:/Users/Josh/Desktop/ne8/metator/html/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</Directory>


Generally you want all routing information encapsulated in the route. I agree with Chris, you should take 100% of what he just said to heart. If youre building your own framework wouldnt the best way to be to start with something existing and identify what it doesnt do that you need it to do, and then extend it from there? If you end up overriding 100% of it then you no longer depend on it. Dont get hung up over "depending on existing code", youre just "using" it today so you can prove your application tomorrow, so you can get paid next week, so you can refactor it next month ( get the idea? ).... be semi-realistic here :-D

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

Posted: Sun Feb 08, 2009 1:49 am
by JAB Creations
I'm not exactly sure what I've said in regards to jobs but my intent right now is to fly solo and build a business; I've I'm doing ok fixing computers at the moment. I could technically just use the single folder file structure in my OP if I really wanted to and I could make it work just fine. However you guys are really pushing frameworks...I'm not going to stop learning so my question is do I really need to learn a frame work for model view controller in the here and now? I'm still not entirely sure what the practical benefits are to an MVC. I've been reading and messing around with this one tonight though girls keep IMing me every ten seconds...
http://www.phpro.org/tutorials/Model-Vi ... r-MVC.html

If an MVC is an important step let me take that one before the frameworks. Once I have MVC in the bag I'll start messing with Zend unless you guys think something else would suite me better. I tend to concentrate on one general project at a time.

One of the things I was thinking about in the back of my head was this might be a method for making all my MySQL calls before any content is generated and thereby potentially reducing the overall number of queries. There was something else too but this related to a thread that was a week or two old when it first crossed my mind. My current system renders the file downwards once...so the file order essentially is the execution order of my site...I'm trying to understand why MVC is useful in it's practical application of usage. I'm not seeing that when I read all these tutorials? For example I understood why I wanted to use relational databases when I grasped the concept of how relational tables and JOIN queries work together...by allowing me to change the user's alias once and having the entire database change automatically with a single write query; that's practical use. Would simply determining what MySQL queries I need first for the page and assigning them to classes be an example of the direction an MVC takes me?

*edit* Also Chris, I threw that class together from what I had already programed. I had it so it would also load the correct base element href for network access (192.168.1.xyz) though did not include it...and then the last else {} bit simply echoed out $_SERVER['HTTP_HOST'].

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

Posted: Sun Feb 08, 2009 2:47 am
by Eran
JAB, you are missing everyone's best intentions here ;)

The point is that learning complicated material such as MVC and design patterns is best done by example. Trying to shoot blindly in the air in the attempt to nail it successively is a very slow method to progress with. If you try one of the better frameworks available (Zend for instance :P), you will learn by example from very mature and factored code right away.

Imagine an architect trying to design a complete city without ever seeing one. The most complicated infrastructure he had seen before was that of a small village. It would be very hard for him to nail all the needs and requirements with best practices of designing a major city. If he could visit such a city and learn its layout, infrastructure and so forth it would be a big help. What if he was presented with a framework for constructing such cities? he would have first-hand resource to rely on for building his own city.

I know from experience, and I believe most everybody here will concur (except for Alex probably) that using a framework was a giant leap forward in software development knowledge and skills. This is why we are encouraging you to do the same.

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

Posted: Sun Feb 08, 2009 4:01 am
by JAB Creations
Ok...then after I regain consciousness I shall tinker with Zend! The downloads page I'm looking at says it's not free though? Hm...guess I'll work out the details when I shift back in to gear later! This is going to be interesting I think...

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

Posted: Sun Feb 08, 2009 4:38 am
by Eran
It's definitely free :P

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

Posted: Sun Feb 08, 2009 5:43 pm
by josh
JAB Creations wrote:though girls keep IMing me every ten seconds...
What can I say? MVC gets the girls every time.

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

Posted: Sun Feb 08, 2009 7:31 pm
by JAB Creations
Full or minimal package? I presume the MVC is part of the minimal package? I'm looking to limit my use Zend to the things you guys think is critical.

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

Posted: Sun Feb 08, 2009 8:28 pm
by josh
Minimal is fine. Full includes their unit tests.

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

Posted: Sun Feb 08, 2009 8:29 pm
by Eran
This information is available at the site however...

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

Posted: Sun Feb 08, 2009 8:38 pm
by JAB Creations
I originally downloaded the minimal package, then the full, and then again the minimal which ended up being 3 megabytes instead of three hundred kilobytes all from the tutorial which naturally failed to suggest which package to download. I've created a public_html and zend folder for security purposes however I can't find the bootstrap.php file (and I obviously searched for it). I'm not exaggerating when I saying I'm really holding my tongue. :|

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

Posted: Sun Feb 08, 2009 8:43 pm
by JAB Creations
No ok I got it...it's not the most intuitive tutorial otherwise it would have told me before creating one file (and thus naturally wanted to open it up and see the results) that we were going to create multiple files.

Working with it...

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

Posted: Sun Feb 08, 2009 9:00 pm
by JAB Creations
Yeah, this is a total mess. So here is my directory structure...

http://localhost/zend/
http://localhost/zend/application/
http://localhost/zend/public_html/
http://localhost/zend/Zend/

I get the following errors and the code isn't familiar to me.
Warning: Zend_Loader::include_once(Zend\Controller\Front.php) [function.Zend-Loader-include-once]: failed to open stream: No such file or directory in D:\local_path_here\\zend\Zend\Loader.php on line 83

Warning: Zend_Loader::include_once() [function.include]: Failed opening 'Zend\Controller\Front.php' for inclusion (include_path='D:\local_path_here\\zend\application\/../library;.;C:\MEDIA\INTERNET\xampp\php\pear\') in D:\local_path_here\\zend\Zend\Loader.php on line 83

Warning: Zend_Loader::require_once(Zend/Exception.php) [function.Zend-Loader-require-once]: failed to open stream: No such file or directory in D:\local_path_here\\zend\Zend\Loader.php on line 87

Fatal error: Zend_Loader::require_once() [function.require]: Failed opening required 'Zend/Exception.php' (include_path='D:\local_path_here\\zend\application\/../library;.;C:\MEDIA\INTERNET\xampp\php\pear\') in D:\local_path_here\\zend\Zend\Loader.php on line 87
It looks like the path is being dynamically generated in index.php though nothing I'm doing works. The tutorial doesn't seem to cover this even though they are encouraging it. :roll:

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

Posted: Sun Feb 08, 2009 9:03 pm
by Benjamin
Zend has a decent codebase, one that I have found to be better than many of the other mainstream frameworks, but I would highly encourage you to look into the symfony framework.

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

Posted: Sun Feb 08, 2009 10:10 pm
by Luke
I do have a very viable and attractive business model that I conjured up in my mind a couple months ago and have been working in a sense towards.
It's not certainly not what most people would imagine but my goal is to do it all on my own without depending on any business partners, investors, and or third party modules (like frameworks and the like)
Sounds pretty contradictory. One word of advice I will give any developer trying to make it in the business world is to stop splitting hairs. You can't afford to be a pedant if you want to make money. When you're doing a project for fun (like your website) you can be as fussy as you want about your code. Clients don't care if you built all the components of their website by yourself.

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