Công nghệ thông tin
HTML Output Class Redefined | HTML Output Class Redefined |
|
|
|
| Thứ sáu, 23 Tháng một 2007 | ||||
Page 2 of 2 Remember how we had to pass those same common variables to every output function we create? There must be a better way to keep track. Consider this. If we add variables to our output class then they will always be available when we need them. So let's create a new output class with the following goals in mind:
The Logic Here's our new logic function. There are a couple of things different here:
function helloLogic( $id, $option, $task, $Itemid ) {The Class There's a lot more going on here than in our old class. We have some object properties (variables). And we have a constructor to instantiate our new class. It looks like a lot but believe me it'll save you alot of headaches in the long run. Plus, you can reuse your new output class and never have to worry about those pesky common variables again. Take a look: class HTML_myOutput {
Pretty much the same. Except we only pass our business data to the function. Everthing else was passed to the output object for consistency. We used our new object properties to create some variables we need in the output. The purist might say we should'nt put code in our output function. But doing so makes things a little cleaner when we're writing the html. <?php function hello( $id ) {Conclusion We created some overhead when we created our new class. But it should make the code more consistant and reliable. Plus, all our common variables will be available in any function we create within the class. There are couple of things to remember about our new class:
I hope the above method will save you some time and headaches when you're writing your next component. I know it worked very well for this me. When you're writing hundreds or thousands of lines of code, every advantage you can find makes life easier for you. Source: http://joomlabr.net Newer news items:
Older news items:
|
||||
| Từ điển thuật ngữ |
| Liên kết Webs |
| Album ảnh |
| Why's luyenkim.net |
| Woman Calendar |
| Cà phê chiều thứ 7 |
| Từ điển LạcViệt Online |
| Kulkul's world |
| www.xahoihoctap.net |