Liquid Fire Posted September 5, 2007 Share Posted September 5, 2007 I am currently building a PHP API for two reason, i am not a big fan of all the current frameworks/API out there(I like codeignitor the best) and well i have the time to build it and think it will be a fun and interesting project(and not a bad thing to have in my portfolio). This is what i am currently thinking of building/have built: <b>database Class(Built):</b> This class currently supports MySQL(tested) and MSSQL/PostSQL(untested) <b>html_element Class(Built):</b> This class will allow you to create any xhtml(gonna change class name) element(a, br, img, etc...) with ease and allows create xhtml strict standard code. <b>table Class(Building):</b> This class make the process of creating a table much easier, it also allows you to create a simple table from a database->get_all_array() result. <b>xhtml Class(Designing):</b> I plan on wrapping the html_element/table class into this class and making this the center class for creating xhtml elements. I will because just add function to this class to create elements which would be a little easier than just using the html_element class, for example: <?php //current way $link_element = new html_element("a", false, array("href"=>"http://www.google.com", "target"=>"_blank"), "Google.com"); $link_element->print_html(); //////////////////////////////////////////////////// //planned new way // method prototype(returns the xhtml) public function link($href, $text, $target = "", $attributes = array()); print $xhtml->link("http://www.google.com", "Google.com", "_blank"); ?> As you can see(or at least my opinion) the second way is a little less code and a bit cleaner to read. <b>session Class(Built):</b> This class just allows you to access the session variables like $session->getUserId();. Calling this class also start the session_start() function. <b>site Class(Built):</b> This is the core of the system(or at least intended to be). This is the one class that is in the system be default the the user should be editing. This class extends from the base_site class which allow you to add css/javascript to the header and will print out the header(from <html> to <body>) and footer(from </body> to </html>). The site class also extends these function so you can add a header/footer(like a image/navigation, basically any html code the is need for the top and bottom of your site). This is where i would suggestion to have all common function that are site specific to you site(like maybe print_news(), of coarse you could easily create a news class if you wanted to). This class is included in every page so that is what it should have common function to login/logout, etc... <b>file Class(Designing):</b> This class is going to handle reading/writing/uploading/downloading files. I am also going to integrate javascript into the framework. For instance you can set a table to allow sorting/coloring/etc..., this can apply to forums and other stuff. I am going to be using jQuery for all my javascript needs. If you have anything i think i need and missed and any other comments, feel free to leave them. If not, thank you for at least reading this. Quote Link to comment Share on other sites More sharing options...
dbo Posted September 8, 2007 Share Posted September 8, 2007 I'm actually doing a similar project right now myself. I just think that most frameworks are "bloatware" and I wanted something with a smaller footprint. Anyways, for me the biggest time sink is input validation. Validating that the input matches my rules and formats, etc. My approach for this uses XML to store the validation rules so that I can generate client and server side validation from the same set of rules... all from the framework. So instead of having a big cluttered up header that does all my vaidation I've got something that looks like this: $xrv = new XMLRuleValidator(); $xrv->load_from_file("xml_validation_rules.xml"); $valid = $xrv->validate_php(); if( !$valid ) { $xrv->display_error_summary(); } That does all my server side vaildation. Then: $xrv->generate_js_validation(); Generates my client side validation. Then all I need to do is put something on the onclick event to call the generated validation. My approach also sorta lets you separate some of the business rules/logic from the code. So anyways, my thoughts are to just target the areas that currently eat up a lot of time. PHP is a good language and I don't want to wrapper every single thing, but if I can identify that I'm spending 80% of development time in 20% of the areas of development (such as input validation) then that's where I'm trying to drive out efficiencies. Quote Link to comment Share on other sites More sharing options...
deadimp Posted September 9, 2007 Share Posted September 9, 2007 I'm also doing the same kinda thing also with Thacmus. I agree with dbo that PHP has a large amount of resources and libraries, and that you don't need to spend too much time re-writing low-level functionality that may have already been implemented. The only time you might need to that if you wish to have your own style, or maybe just an implementation for practice's sake, but if it's different styling you're after, a basic wrapper could do that for you. Just don't go crazy with it all. For your html/xhtml classes, you ought to look into DOM and SimpleXML under the PHP documentation. As for the session class, I'm not sure you'll really need it if it's just a different venue for $_SESSION. When you design a wrapper for something, you generally want to make it so that it's easier / more compact to do something (and make it easy to change the low-level stuff without really having to change much else). Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted September 10, 2007 Author Share Posted September 10, 2007 Thanks for the input, let me go over a few points you guys have made. First let me just say that there are 3 major things i want to be able to accomplish with this API I am developing: 1. Roll redundant tasks i seem to perform a lot at work and home. For instance at work I find people always asking for an excel sheet from a database query. I may not do this at home(never has) but I feel that it is worth the time to create a class to create this excel file(One future project will require this feature). 2. Avoid simple mistakes. This is the biggest reason for the (x)html class. One thing that i sometimes do is forget to close a tr or add an alt for an img tag which causes the code to be invalid(kinda like me forget to put a semi-colon in php/javscript). Having a class will make sure the code is always valid. 3. Make me code less and get the same result and following the top 2 things above(like writing the html code plain would be less code than using the class(sometimes) but then I am not doing the first 2 things). The session class in mainly to have it fit in with the rest of the system in how to retrieve data. I also am going to make a base_data class that any data based object should extend from. In that base_data class will be defined the __call method to allow get_user_id(), set_user_id()(basically get/set and then the field name). Also I have to do session_start() anyways so $session = new session() is not really that much for code. As for my (x)html classes, I don't see how PHP DOM or SimpleXML would help me with what i am doing, I am not really dealing with XML and those seem to deal with XML(grant you (x)html is similar to XML but they are not the same). I was just thinking about the xhtml class that would act as a wrapping for all my (x)html classes and thinking if i really needed it. The bottom line that is that i realized that the wrapper class would allow for me to do the same thing with the html_element but will less code. for instance <?php //plain html_element class $div = new html_element("div", false, array(), "test"); $div->print_html(); //new xhtml_class $xhtml->div(array(), "test")->print_html(); ?> the second set of code will do the same exact thing as the first one but the second one it a lot cleaner and smaller. Thanks for all the input and i look forward to getting some more. Quote Link to comment Share on other sites More sharing options...
dbo Posted September 10, 2007 Share Posted September 10, 2007 I thought about developing an html/xhtml class to generate well formed tags and what not but then decided against it, and let me tell you why. Often times the guy doing the development is a different guy than is doing the design. Designers know HTML/CSS etc. If you have a bunch of intermingled PHP code inside of your design they're not going to be able to work with it nearly as easily. So what I decided to do was sorta take the ASP.NET approach (don't shoot me ). So I've got a filename.source.php and a filename.design.php. The source contains any programming logic and the design is the HTML stuff with only PHP that relates to layout. I use a lot of the same concepts as smarty but without forcing the smarty framework/engine on a user. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted September 10, 2007 Author Share Posted September 10, 2007 That is a pretty good point to consider. I personally don't like template system like smarty, then again I am a stronger programmer than designer. Quote Link to comment Share on other sites More sharing options...
deadimp Posted September 10, 2007 Share Posted September 10, 2007 I honestly don't see the need for a templating engine, unless you're allowing for custom pages and you need security. I just use PHP short-tags for small amounts of content (<?=$var?>). Liquid Fire << If you're worried about messing up your HTML code, use a validator. The extension for Firefox is extremely helpful, in addition to the sytnax highlighting for the source view, and especially FireBug. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted September 10, 2007 Author Share Posted September 10, 2007 deadimp, I always use the w3c validator, I just want to make the process automatic. While it will not save alot of time, it will save some time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.