PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Nov 18, 2017 7:10 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Framework for Business
PostPosted: Thu Aug 30, 2007 8:46 am 
Offline
Forum Commoner

Joined: Sat Mar 13, 2004 11:21 pm
Posts: 66
Location: UK
I have been working on a framework for about 3 years now and have used what I have made on over 40 websites as I work for a professional web design agency. There are clear patterns in what I do for clients and they all tend to need the same sort of things in the core but a different way of outputting and managing what they publish.

The framework I have built has been successful in allowing me to create business directories, shops and other online solutions in less than 2 weeks allowing me to take it easy when creating a website, in addition to this, I can also get a website online in a fairly small amount of time depending on how urgent it is. Although I am pretty sure some of you will be able to do the same, the whole idea of using an efficient framework should have crossed every PHP developers mind at some point.

The reason I am here now writing all of this crap, is because I am converting everything to OOP and I am also going to release the framework at some point next year. I am not a believer in BETA crap because the framework will be tested over time and modified and improved as time goes on and more suggestions come in.

Getting to the theory point of all of this, I am looking for people work with PHP on large projects (defining large as websites with over 1000 publicly accessible pages and a complete backend admin) to answer one simple question, but in a lot of depth:

What functionality do you need for every website you create which you constantly have written in the past or have replaced with your own basic starting point?


Top
 Profile  
 
 Post subject: EXAMPLE
PostPosted: Thu Aug 30, 2007 8:52 am 
Offline
Forum Commoner

Joined: Sat Mar 13, 2004 11:21 pm
Posts: 66
Location: UK
I will start by providing a real example of what I deal with in every case.

A session management system which deals with users signing in and signing out on a daily basis:
  • Including user banning, password resetting and account validation by e-mail.
  • In addition to this, the choice of either 1 global user or many seperate users.
  • Multiple sessions for user accounts or 1 session per user.
  • Session time limit
  • Ability to end sessions


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 10:34 am 
Offline
DevNet Master
User avatar

Joined: Wed Dec 06, 2006 5:14 pm
Posts: 3635
Location: Toronto, Canada
<long post deleted>

Rails.


Top
 Profile  
 
PostPosted: Thu Aug 30, 2007 5:17 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13443
Location: New York, NY, US
Bon Bon wrote:
What functionality do you need for every website you create which you constantly have written in the past or have replaced with your own basic starting point?

I am a little confused by this statement. I understand the functionality for every website I create. The "constantly have written in the past" doesn't make sense to me. I understand that I am replacing something, but don't understand what my "own basic starting point" might be.

Your session management system sounds like a user account system, but has some conflicting things like one or many accounts. Can you restate your question for slightly dim folks like me?

_________________
(#10850)


Last edited by Christopher on Thu Aug 30, 2007 5:41 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 5:38 pm 
Offline
Tranquility In Moderation
User avatar

Joined: Sun Feb 06, 2005 8:18 pm
Posts: 5001
Location: Indiana
Database wrapper. Querying, result sets, pagination, num rows, fetching.

_________________
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 3:18 am 
Offline
Forum Commoner

Joined: Sat Mar 13, 2004 11:21 pm
Posts: 66
Location: UK
The session manager and account manager interlink into each other, which is why they can be listed together. The whole point of the framework is to link everything together but keep it effcient without cramming it with functions that nobody is ever going to use, which is how it currently works for me but to release it to the public I presume that people are going to want a bit more.

An example of what I do not want is qcodo:
Syntax: [ Download ] [ Hide ]
$this->btnAdd = new Qbutton($this);
$this->btnAdd->Text = 'Click me';
$this->btnAdd->AddAction(new QClickEvent(), new QServerAction('btnAdd_Click'));

As businesses want rapid deployment, and I am trying to keep things tidy, my version will look something like this:
Syntax: [ Download ] [ Hide ]
$form->addSpecial('submit', 'Click me', 'submit', 'id="btn_submit"');

Which is simply a clone of what I already have but converted to a class.

void addSpecial(string $name, string $value, string $type[, string $attributes])

Add special can be used to add hidden fields, input fields, password fields and checkboxes. Rather than having one function for each when they would be doing the same thing. So thus becoming a special blend of an add method. There are others such as addRadioBtn() and addSelectList().

Here are a simplified list of what I already have:
  • Session manager
  • Account manager
  • Database manager
  • Form builder
  • File uploads
  • Image manipulation
  • Configuration manager
  • HTML Tidy (written in PHP, not using Raggett's HTML Tidy) + HTML Validator
What I am asking for is what else, in the core of every website you build, would you like to see in something like this. Although the framework will not be truely object orientated, it will take advantage of what I feel are the best benefits of using objects. In addition to this, there are a few secret features that I am not telling people about yet as I am going to use these to help promote the launch of the framework and CMS.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 31, 2007 11:55 am 
Offline
Site Admin

Joined: Thu Apr 18, 2002 3:14 pm
Posts: 1767
Location: Montreal, CA
I generally hate frameworks for the very reason people supposedly love them. Most often, the popular frameworks try to making things generally easy, but specifically dumb. A framework should do a lot of smart things naturally for me. For example:

Syntax: [ Download ] [ Hide ]
$form->addSpecial('submit', 'Click me', 'submit', 'id="btn_submit"');


This doesn't make any sense. First, it requires a learn a completely new lingo. What is a special and why do I want to add it? I want to add a submit button. And why on earth is 'submit' in there twice. It doesn't make sense. And then there is an ID, which does me little good. I'm building an application with a framework. Here's a better way to handle this.

Syntax: [ Download ] [ Hide ]
$form->addSubmitButton('Click me');


There. Much easier, much less confusing, and much less troublesome. It also makes sense. The framework should be the one handling ID's and names and types. Not me. That's the point of a framework. Most frameworks force you to handle creation of the scaffolding, or the details. I don't want to deal with the details if I'm using a framework. The framework should have some balls and say "I'm made for building web sites!" and then focus on that. The framework shouldn't support other weird off-color things, just deal with making a web site.

Also, while I did use the php code above and suggest a replacement, it was only because it was easily available. A framework shouldn't deal with things it shouldn't have to. If I'm working with HTML, I should be working in HTML. A PHP framework should do as little as possible outside it's realm. What this means is rather than have to write:

Syntax: [ Download ] [ Hide ]
$form->addSubmitButton('Click me');


I should be able to work in HTML directly. This might mean the resulting code is longer, but it makes more sense. Consider this: your framework builds around the simple concept that HTML is HTML, JavaScript is JavaScript, and the framework doesn't try to build that. It assumes that you know what you are doing. What the framework does it bring it all together and doesn't fudge it up. So suddenly in your directory structure, you have a /forms/ directory that you place all your forms in. So suddenly rather than needing to use PHP to type out all your form functionality, you just get your form functionality from the form itself. And assuming that the HTML is well-formed, you can have the framework parse the file and generate a HTML+PHP cached copy on the server that it uses to dynamically render each time. After all, you can program the system to enter the value in this code:

Syntax: [ Download ] [ Hide ]
<input type="text" name="item" value="">


This is better than requiring people to do this:

Syntax: [ Download ] [ Hide ]
<input type="text" name="item" value="<?php echo $this->value; ?>">


Why don't you see this? Laziness. Heck, I've never done it because it would require extra work that I really don't want to involve myself with.

Basically, the point is, a Framework should do the work it can while at the same time not changing the way you work. Let people who've learned HTML write HTML, who've learned JavaScript write JavaScript. One of my most favorite frameworks that I've built for work I've done is a reporting class that has slowly evolved into a monster. But it gets the job done and stays out of the way.

First, it assumes that you are creating a report from a database (though I could easily hack it to use something else). Secondly, it assumes you've already connected to the database. Finally, it assumes that you might want more than one report on a page. Basically, to great a paginated report you do something like this:

Syntax: [ Download ] [ Hide ]

<?php

$Report = new Report("Quick User Display");

$Report->useTables("users, user_details");

$Report->fetchCol("id");

$Report->displayCol("username as Username");

$Report->displayCol("email as Email Address");

$Report->displayCol("logins as Login Count");

$Report->makeSearchable();

$Report->makeSortable();

$Report->setHandlerFor('username','makeUsernameLinkable');

$Report->cache(60);

$Report->generateReport();



function makeUsernameLinkable ( $username, $record, $rs ) {

    return '<a href="Users.php?id='.$record['id'].'">'.$username.'</a>';

}



?>

 


This code does several things that makes things easy for the user. First, it will handle generating the HTML table using appropriate ID and CLASS attributes that allow for complete customization. Also, it determines how to link the two tables together (with ID in this case). By following a common sense standard in the database, you can have a framework that makes assumptions. This assumption is that 'id' is the PK, and something like 'user_id' is the FK. The real magic happens with makeSearchable and makeSortable. They do exactly what you think they do. They make the report searchable by the user and it also makes each header sortable. The framework automatically fills in the needed information so the user has the ability to search any of the fields (or all of them). Of course, it can also sort by each of the fields. By default, the framework is set to display 20 items per page, and handles pagination. And while it generates all the fields and IDs for you using known methods, it ensures that each report on a page doesn't affect other reports. So it doesn't use a generate "next_page" GET value (as that would affect all reports on a page, should you have more than one).

It also allows you to set a handler for any field. In this case the handler is for the username, and it makes the username a link. The framework also provides a method to cache your basic searches (It doesn't cache searchable reports 'yet', but I included it as an example).

But even this framework suffers a bit. I haven't built in the ability to use your own SQL, though this is again merely because I'm lazy, and haven't found a real need for it yet. Also, the HTML is currently hardcoded, but it wouldn't be much trouble to abstract it out (I actually started doing that, but it was boring). However, the generated HTML is pretty much what you'd get out of a table anyways, so it doesn't matter to me.

The point is, I make a lot of simple assumptions, but I believe all the assumptions are smart assumptions. A good Framework let's you get away with using these assumptions without knowing about it. A framework shouldn't require additional work simply because it's easier to program. Honestly, you say you have a framework you use now, it works well, but you suddenly want to convert it to an OO system. Why? The best frameworks I've seen are those that are designed by people who use it to create something rather than create the framework to create a framework. It's part of the reason Rails is so popular for Ruby (despite the fact that it doesn't do things the way I would do them in certain cases). Rails was created by people who were actively creating a framework not to release a framework, but working on a real project that used the framework. The result was a set of code that worked for them.

I loathe to see another Rails-like framework. Rails exists, and it exists in part in PHP as well. If someone wants to use PHP and Rails, they have their options. But frameworks shouldn't try to be everything for everyone. Rather, it should just flat out say "smurf you, this is the way I do it, it works for people who work with me. If you don't like it, go find another framework." Give you framework attitude. Let it make assumptions. Make it work for you. If other people find it useful, great! If not, who cares? You are getting work done while they are playing with FrameworkOfTheMonth.[/syntax]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 5:52 am 
Offline
Forum Commoner

Joined: Sat Mar 13, 2004 11:21 pm
Posts: 66
Location: UK
Cheers for the comments.

I think you have a lot of valid points and this is the right kind of thing I was looking for.

Regards to the HTML rendering and splitting the forms into their own folder, this has already been achieved in the framework.

I am going to leave the input special but also add a function just like what you have mentioned and I might even remove my function once I have completely replaced it. But here is the current addSpecial function:
Syntax: [ Download ] [ Hide ]
function mk_input_special ($name, $value, $type, $attributes = '') {

  if (isset($_POST[$name])) $value = clean(stripslashes($_POST[$name]));

  $input_field = '<input name="' . $name . '" type="' . $type . '" value="' . $value . '"';

  $input_field .= empty($attributes) ? ' />' : " $attributes />";

  return $input_field;

}

I think it is a good point you mention about letting the framework do all the id handling, in addition to this I am going to chuck in a few things I already have made to extend this further.

Regards to your:
Syntax: [ Download ] [ Hide ]
$Report->displayCol("username as Username");

$Report->displayCol("email as Email Address");

$Report->displayCol("logins as Login Count");

This is something I am trying to avoid where I can, instead my system which is somewhat similar does this instead:
Syntax: [ Download ] [ Hide ]
$x->fetchFromTable('test');

$x->fetchField('x') // optimised for 1 column

$x->fetchFields('x', 'y', 'z'); // optimised for many

The example has gave me some ideas on how to improve the framework, things that I overlooked like sorting, I totally missed this from the new framework and the old framework depended on knowing SQL.

Regards to the HTML, I have provided 3 ways in which to create a page, firstly create the page in Dreamweaver etc (or hardcoded) and upload it using the file manager, secondly using the WYSIWYG interface which has been asked for on many ocasions (which is why I am adding it) and in addition to this, the framework can use a template and insert elements to create a page. Although the first is not entirely complete, the other 2 work like a dream for me and I want to extend the experience so I can please as many people as possible. A lot of functionality is happening behind the scene to ensure a flexible template and skinning system.

I am not using a framework to create a framework, I am making everything OOP due to the fact that it solves some problems I have always had and with the PHP 4 to 5 switchover making good press I thought now would be the best time to do this.

I must be honest that I looked at Rails and did not like it, although you would hate to see something similar coming out, what I am doing is a bit like Rails but with PHP syntax as I hate the Rails syntax. The main objective of this framework is to get what I want out of it as I do similar sorts of things all of the time, although I am wanting to make it more of a community kind of thing too and release the framework to the public.

I see this as something that will be big, as I am doing some unique but clever things myself that I am fairly sure nobody else has done. My ideas might not be for everyone but hopefully things will suite most people. Cheers again.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 8:27 pm 
Offline
Forum Regular

Joined: Wed Dec 13, 2006 11:28 am
Posts: 575
With regards to your input thing, I think it would be a lot better if you had a separate method for each input type. Yeah, its a lot more methods to write, but you only have to write them once. Secondly you can then have other options that are specific to the type of input. For instance the checkbox should have the option for checked or unchecked instead of having to pass that in the attributes. It would make a lot more sense to have it be a boolean.

One advantage I would see from this is that there would be no need to memorize what inputs are available, less room for typos (your code as you posted would happily let me create an input of type 'select' or type 'textt'). Think of your framework being a user interface, it needs to be user friendly, and in order to allow for a programmer (user) to develop rapidly in the framework it needs to be able to throw exceptions if it is used wrong and not require memorization of options. There is nothing that makes me hate a framework or class more than having to memorize a list of valid parameters and then doesn't crap out when I enter in something wrong.

Next I would make the attributes be an array, again this is for readability and for error catching. You could go so far as to make sure that the attribute names and values are valid (like throw an exception if someone tries to pass in text for maxlength). Again, this will make the framework more 'user' friendly by catching markup and coding errors before the form is rendered as html.


compare this:

Syntax: [ Download ] [ Hide ]
$form->mk_input_special ('firstName', 'fred', 'text', 'size="3" maxlength="5"') ;

$form->mk_input_special ('canLogin', null, 'checkbox', 'checked') ;


to this:

Syntax: [ Download ] [ Hide ]
$form->addInputText('firstName', 'fred', array('size'=>3,'maxlength'=>5)) ;

$form->addInputCheckbox('canLogin', true) ;



You could even make it so you could retrieve references to the inputs as objects

Syntax: [ Download ] [ Hide ]
$firstName = $form->addInput('firstName', 'fred') ;

$firstName->size = 3 ;

$firstName->maxlength = 5 ;


If you had it so the form objects had all the possible attributes declared as properties or methods and i used your framework, I would never need to pull out an HTML manual and look up forms, code insight would tell me everything.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 9:33 pm 
Offline
Tranquility In Moderation
User avatar

Joined: Sun Feb 06, 2005 8:18 pm
Posts: 5001
Location: Indiana
I haven't seen a form handler yet that would inspire me to use it. Nothing gives me all of the options coding plain HTML would. And if it did, it would be just as much or more markup to create it, AND more complex learning the form handler object(s).

_________________
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 12:43 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13443
Location: New York, NY, US
I agree with scottayy. I am much less interested in a form manager that generates HTML than one that makes input filtering/validation easy, nice error message management, and determining when he form is properly submitted. I do most stuff in HTML as well. I generate selects, radios and textboxes out of necessity to set their selected/checked state, but would rather not do even that...

_________________
(#10850)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 04, 2007 6:13 am 
Offline
Forum Commoner

Joined: Sat Mar 13, 2004 11:21 pm
Posts: 66
Location: UK
All but the input tag form controls do have their own method, I did say that I would be replacing this with separate methods for each type of input (ie submit, reset, hidden), and I also said that I would not be removing the addSpecial method until I was satisfied that it had been replaced by something robust.

The form control draws controls on a web page, knows how many posts it should be capturing and also where the post is coming from, this enables everything to be more secure. Then you can check specific controls to ensure they contain data and of the right type (such as e-mail addresses etc).

If anything is wrong all the values are then included when the form is drawn again with error messages, all managed by adding form controls.

So the form control is making things easier, I am just working out how to allow the flexibility of the old system in the new system.

It took a few hours last night making sure my naming conventions for the database class were correctly describing what they were doing.

So basically, this is what the form control now looks like (theory, not implemented yet):
Syntax: [ Download ] [ Hide ]
$form->addSubmit('Update Details');

void addSubmit ( string $text [, string $attributes] )

In addition to this:
Syntax: [ Download ] [ Hide ]
$form->addTextbox('Your full name', 'Type your full name including any middle names you have');

$form->addTextbox('E-mail address', 'Type your e-mail address', TRUE, $form->EMAIL_MASK);

void addTextbox ( [string $label [, string $defaultText [, bool $required [, string $mask [, string $attributes]]]]] )


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 10:47 am 
Offline
Forum Commoner

Joined: Sat Mar 13, 2004 11:21 pm
Posts: 66
Location: UK
Basically I have completed the database class now, regards to version numbering, I expect this project to get large and a lot of regular changes will happen to improve the framework.

What is the best way to number each version?

I will include the class if you want so that people can see this is serious and not no mickey mouse crap.

In addition to this, this thread has currently gone dead, please provide me more feedback because I am lost without you all in this case.

Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 11:51 am 
Offline
Forum Regular

Joined: Wed Dec 13, 2006 11:28 am
Posts: 575
For more feedback perhaps you should post some source code or a subversion repository or something.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 12:55 pm 
Offline
The Ninja Space Mod
User avatar

Joined: Fri Aug 05, 2005 1:53 pm
Posts: 6424
Location: Paradise, CA
I agree with arborint about generating forms with your forms library. I don't really see it as necessary or even possible to generate any type of complex form (just ask ole - LOL). I like being in control of my HTML just about 100%. Like arborint says, sometimes it's necessary to generate form elements such as selects, radios and checkboxes, but that's simply because of their nature. Other than that, it's pretty useless imho.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group