Page 3 of 6

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

Posted: Sat Feb 07, 2009 2:10 am
by Chris Corbyn
josh wrote:As far as implementing your own MVC its definitely doable, but itd be like trying to learn about polymorphism by writing an object compiler. Definitely doable but IMO not the way to learn.
I sort of disagree here, though I see what you're getting at. Stripped down to it's extremely bare essentials, MVC is not that complex. You can distill it down to a one-page example (no front controller or other bits and pieces).

We can work through the raw basics of it (and I mean really basic) here. Let's take a simple example. Forgetting the rest of the application, and imagining that this is just one page...

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.

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

Posted: Sat Feb 07, 2009 2:45 am
by JAB Creations
Ha! I'm watching the video and it's funny that I've been simultaneously working on this.

I have been independently working towards a single file to dynamically handle all URL's. The screencast (nice to know a new term) is exceptionally helpful at least thus far in the first video.

One of the things I'm actually working with is exploring how I'm going to handle HTTP queries and such. I think he covers that in video two. My consciousness will be declining for the evening soon though I'll try to absorb as much as I can right before the sun rises. It burns! It burns! :twisted: Oh and thanks for posting the links. :)

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

Posted: Sat Feb 07, 2009 2:51 am
by JAB Creations
Chris, somehow missed your post...I'm definitely aiming and have been making good progress towards having my site be entirely database driven save for some bits stored in PHP of course.

Fruits...hmm, maybe we could work with a registered members list? I know some of you want me to stop using LEFT JOINS all the time so maybe I could do something like only show a list of users who actively post on the forums (forum count) and then show only users who have this or that attribute associated with their account?

I've got to finish watching these screencasts, eat, and crash but I'm definitely excited about all of this now since I seemed to be moving in this direction to begin with! :)

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

Posted: Sat Feb 07, 2009 3:06 am
by josh
JAB Creations wrote:I know some of you want me to stop using LEFT JOINS all the time so maybe I could do something like only show a list of users who actively post on the forums (forum count) and then show only users who have this or that attribute associated with their account?
http://framework.zend.com/apidoc/core/Z ... elect.html

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

Posted: Sat Feb 07, 2009 3:31 am
by JAB Creations
I've watched the first three videos and am considering watching the fourth tomorrow. Thanks for posting the Zend links though I do plan on implementing my own system from scratch to better understand it.

I am comfortable enough to say I think I have the dynamic to static URL scheme figured out already.

The next step is to determine what "section" they need. Conceptually I think it works out to something along the following lines which I'm going to try tomorrow after I wake up unless replies suggest otherwise...

1.) Intercept the HTTP query, example...

Code: Select all

<?php
echo '<div>'.$_SERVER['argv'][0].'</div>';
echo '<div>'.$_SERVER['argv'][1].'</div>';
?>
2.) After explode, split, whatever I'll determine the section (blog, forum, etc) the user requested...if it's in the database good, else work with error handling.

3.) After I know the section I need to know the page.

4.) After the page I need to determine what if any queries were requested.

I think has the possibility to break away from the traditional HTTP queries I've been using though I'm not absolutely sure.

For example this is a static URL to a static file (that physically exists at that location)...
http://www.jabcreations.com/blog/?audio ... owerkeys=1

...what I need to do is figure out if that same URL will be able to process the $_GET HTTP queries the same or if I'm going to have to do things a little differently.

I think I'm headed in the right direction and I don't mind the complexity of not relying on any third party frameworks though for now chicken sounds best. :) Thanks for your posts and Josh for the videos. I know have a better understanding of what Zend is actually used for at least to some vague extent.

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

Posted: Sat Feb 07, 2009 3:47 pm
by josh
JAB Creations wrote:I think I'm headed in the right direction and I don't mind the complexity of not relying on any third party frameworks though for now chicken sounds best. :) Thanks for your posts and Josh for the videos. I know have a better understanding of what Zend is actually used for at least to some vague extent.
I think are in the right direction but you have much work to do. See this is why I _don't_ recommend rolling your own. It's doable but do you want to spend 2yrs learning this stuff or 2months? When I first began with frameworks I started rolling my own Front Controller. It worked. but big mistake. I think letting go of this instintic naive urge to build our own frameworks right off the bat is a good thing. We try to re-implement too many wheels. For instance instead of re-inventing the router why not use the already made router, Jab? http://framework.zend.com/manual/en/zen ... outer.html

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

Posted: Sat Feb 07, 2009 4:18 pm
by JAB Creations
Too much work? Look at all I've done already! I love doing this stuff and besides, if I have to depend on other people I won't be able to depend on myself. While I'm writing my own blog, forum, chat room, polls, etc to get away from third party module dependence why would I want to introduce new dependencies? I live at home, free rent, no bills, and have the will power and time to do this right the first time around and dependency and trust in others has been nothing except a burden. I'll use a framework only when it's purely an optional feature which limits it to clientside and DHTML effects (jQuery in example). I do appreciate your suggestions though Josh, I don't want you to think otherwise.

Creating the "bootstrap" and file extension exceptions...

.htaccess

Code: Select all

<ifmodule mod_rewrite.c>
  RewriteEngine on      
  RewriteRule !\.(css|cur|exe|gif|gz|html|h3m|ico|jpg|js|mov|mp3|mp4|msi|pdf|pl|png|rar|swf|ttf|txt|wmv|xhtml|xml|xpi|zip)$ page.php
</ifmodule>
I can think of some reasons why I'd want to remove some of the extensions though this will do for now. I do have a question though...is there a way I can add a .htaccess file with an exception in sub-folders that negates this altogether as my live site has some FTP accounts for friends?

I'm now working on constructing the first class to determine the section, file, and queries and will post that soon. :)

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

Posted: Sat Feb 07, 2009 4:21 pm
by JAB Creations
Looks like I found an example...

Code: Select all

<ifmodule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^friend1/ - [L]
  RewriteRule ^friend2/ - [L]
  RewriteRule !\.(css|cur|exe|gif|gz|html|h3m|ico|jpg|js|mov|mp3|mp4|msi|pdf|pl|png|rar|swf|ttf|txt|wmv|xhtml|xml|xpi|zip)$ page.php
</ifmodule>

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

Posted: Sat Feb 07, 2009 4:23 pm
by Eran
is there a way I can add a .htaccess file with an exception in sub-folders that negates this altogether as my live site has some FTP accounts for friends?
The rewrite module only runs for requests issued from apache (http) and should not affect FTP in any way. Regardless, you can put in any sub directory an .htaccess with the directive "RewriteEngine off" and it will disregard lower directory .htaccess files.

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

Posted: Sat Feb 07, 2009 4:29 pm
by JAB Creations
pytrin wrote:Regardless, you can put in any sub directory an .htaccess with the directive "RewriteEngine off" and it will disregard lower directory .htaccess files.
Duh! I should have thought about that! Thanks for bringing it to my attention!

Here is an improvement over the single line per exception and it seems to work fine at least locally on my XAMPP WAMP sever...

Code: Select all

<ifmodule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^(friend1/|friend2/|friend3/|friend4/) - [L]
  RewriteRule !\.(css|cur|exe|gif|gz|html|h3m|ico|jpg|js|mov|mp3|mp4|msi|pdf|pl|png|rar|swf|ttf|txt|wmv|xhtml|xml|xpi|zip)$ page.php
</ifmodule>

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

Posted: Sat Feb 07, 2009 4:59 pm
by josh
JAB Creations wrote:Too much work? Look at all I've done already! I love doing this stuff and besides, if I have to depend on other people I won't be able to depend on myself. While I'm writing my own blog, forum, chat room, polls, etc to get away from third party module dependence why would I want to introduce new dependencies? I live at home, free rent, no bills, and have the will power and time to do this right the first time around and dependency and trust in others has been nothing except a burden. I'll use a framework only when it's purely an optional feature which limits it to clientside and DHTML effects (jQuery in example). I do appreciate your suggestions though Josh, I don't want you to think otherwise.
So because your time is plentiful you'd rather spend it reinventing the wheel instead of leveraging the existing wheel to help people? Too much work? naw... I understand you implemented a rewrite rule, but does your solution allow filtering routes? Does it allow generating routes from view scripts? Does it allow forwarding between routes without sending a header() redirect? It's not a matter of how much work how much dependencies, its a matter of you are currently learning to "crawl" and you're trying to write a book about running, or that's how I felt after I sank a ton of time into my own framework then eventually switched to Zend. Why not learn a framework which would take a month or 2 instead of trying to create one which would take a year or two. MVC in itself is easy to understand sure, but until you've tried to use a framework you will have no idea the purpose of the features of the framework. FOr instance before you write a front controller you need to learn about the dispatch loop, plugins / filters, controller actions, routing, various design patterns & best practices, etc...

If you know how to use ZF you could create a blog in a day, then you could go subclass the framework and eventually refactor out the framework _while your application is live_. Whatever gets my app to market fastest at the end of the day without negatively affecting quality, takes my cake. I can always get rid of it later, thats what refactoring is for. If you depend on other people's code you may have to subclass it here and there to get it to do what you want, but I don't view it as a dependency since software is supposed to be, well, soft. It's not a dependency its just a matter of getting over a hangup about code re-use. All I'm saying is don't think like a programmer. If you want 0 dependencies you should go build your own CPU :D

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

Posted: Sat Feb 07, 2009 5:14 pm
by Eran
I think the point is, that a mature framework like ZF is the result of thousands of cumulative work-hours from some of the best and most experienced PHP developers. It is backed by thousands of unit-tests and is tested in real-world situations daily in hundreds of thousands installations world-wide, all of which can submit their own bug reports.

After you have learned it inside and out, you'll be in a much better position to build your own. I guarantee it will probably be the biggest boost to your development skills that you've had to date.

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

Posted: Sat Feb 07, 2009 5:18 pm
by josh
I agree, just dont get yourself hung up on pointless stuff. I showed ZF to one guy and he came back a month later asking me about postresql? I was like wtf hes like well i was following thru the manual word for word and it talks about postresql before mysql :banghead: ( not that theres anything wrong with postresql, but it has nothing to do with his end goal of learning about frameworks )

I'd say the relevant bits are the MVC component, the sub-systems of that component such as view helpers, routers, etc... and "middle level" SQL abstraction stuff like Zend_Db_Select

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

Posted: Sat Feb 07, 2009 6:32 pm
by VladSun
:offtopic:
JAB Creations wrote:I won't be shy about admitting it, I've unfortunately driven Vladsun crazy in plenty of threads because he's great with concepts while they fly over my head.
No, I'm not good at design or concepts. I know I'm not good.

What's driving me "crazy' is:

Jab: I have done A and I want to do B. How I should do B?
Vlad: You have done A in a wrong way. Consider rewriting A this way '...', then B could be done easily this way '...'
Jab: No, I want to do B, while keeping A untouched!
Vlad: [going crazy :) ]

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

Posted: Sat Feb 07, 2009 8:12 pm
by JAB Creations
I'm not debating if Zend is awesome, useful, etc. I don't see how what I'm doing is in any way overly complicated to begin with. Then why would you link to Zend's documentation for MySQL? I didn't get the job while doing the internship because of my inexperience with MySQL...so why start writing pseudo-MySQL? Since I would minimally use Zend if I used it any way I'd be loading lots of resources for only a limited few reasons.

I'd like the time to work on this and to see how I can get this to work. I'm making a simple model view controller, not a framework. If it turns out I need something more complex I'll consider it, how's that? :P

How does this look for starters? :)

.htaccess

Code: Select all

<ifmodule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^(friend1/|friend2/|friend3/) - [L]
  RewriteRule !\.(css|cur|exe|gif|gz|html|h3m|ico|jpg|js|mov|mp3|mp4|msi|pdf|pl|png|rar|swf|ttf|txt|wmv|xhtml|xml|xpi|zip)$ index.php
</ifmodule>
index.php

Code: Select all

<?php
class cms
{
 public function set($name,$value) {$this->$name = $value;}
 public function get($name){return $this->$name;}
}
 
function cms_base($part)
{
     if ($_SERVER['HTTP_HOST'] == "www.jabcreations.net") {if ($part == '1') {return 'http://www.jabcreations.net';} else if ($part == '2') {return '';}}
else if ($_SERVER['HTTP_HOST'] == "www.jabcreations.com") {if ($part == '1') {return 'http://www.jabcreations.com';} else if ($part == '2') {return '';}}
else if ($_SERVER['HTTP_HOST'] == "localhost") {if ($part == '1') {return 'http://localhost/';} else if ($part == '2') {return 'Version 2.9.A.3';}}
}
 
$cms = new cms();
$cms->set('base1',cms_base('1'));
$cms->set('base2',cms_base('2'));
$pieces = explode($cms->get('base2'), urldecode($_SERVER['REQUEST_URI']));
$url = explode('/', $pieces[1]);
$page = explode('?', $url[2]);
$cms->set('section',$url[1]);
$cms->set('page',$page[0]);
 
echo '<div><b>Requested Section:</b> '.$cms->get('section').'</div>';
echo '<div><b>Requested Page:</b> '.$cms->get('page').'</div>';
?>
It's still a bit static if I want to add multi-directory-depth support so-to-speak. It comes down to how I want URL's to look in the address bar. For now though this works!

What I'm interested in now is a little direction in to how I should approach the next step for creating my own model view controller. Chris suggested working on a site that sells fruit I think...so long as it's pulling something from a database I'm happy to just mess with it and see where this goes. Thoughts please?