|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sweatje Smarty Regular
Joined: 17 Apr 2003 Posts: 70 Location: Bettendorf, Iowa, USA
|
Posted: Thu May 15, 2003 9:45 pm Post subject: |
|
|
For comparison sake, here is an example of a Model method retrieving data. Actually reasonably complicated because it uses bind variables as well:
Code: | /**
* retrieve daily catalog history
* @return array
*/
function GetCatlgDailyHist($psCatlg, $psPlant, $piDays=91)
{
$o_conn = amp_adodb_connection('prdqry');
$a_bind = array('CATLG' => $psCatlg, 'PLANT' => $psPlant, 'DAYS' => $piDays);
$o_rs = $o_conn->Execute(PLANT_CATLG_HIST_DAY_SQL, $a_bind);
if ($o_rs && !$o_rs->EOF) {
return $o_rs->GetArray();
} else {
trigger_error(DB_OOPS);
return false;
}
}
|
I tend to code the SQL statements themselves as constants before the class definition.
By "MVC mindset" I mean at least structuring you code so that data/file access and other business logic is handled in on portion of your code (Models). Application flow and security by another (Controller), and finally presentation logic in a final portion of your code (Views).
I have settled down on using ADOdb for db abstraction, Phrame for a base MVC framework and Smarty for HTML rendering in views. Once you get used to how the framework works, most of the code you write is in small tight blocks, and maintenance has not been an issue.
I have written a two part series documenting this setup for PHP|Architect. Part 1 was the lead story for the May issues, Part 2 will be coming out in June. _________________ Jason
jsweat_php AT yahoo DOT com |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri May 16, 2003 2:56 am Post subject: |
|
|
I think that the crucial difference in sweatje's approach as compared to toma's is the idea of an abstracted data layer as opposed to the abstraction of the db handling code (the driver code).
In toma's approach, you still code your application logic directly against the database -- except that instead of using native db calls you are using abstracted calls. The principle behind sweatje's approach is that your application logic doesn't directly call the db handlers whether abstracted or direct. Instead your application calls "business" objects in the data layer that handle the necessary data retrieval. This provides a much higher degree of code separation and makes things like migration and scaling far simpler.
I prefer the latter approach. It means that the "extended functionality" (like associative keys, etc) can be removed from the db abstraction layer and put into your data abstraction layer as can your error handlers, etc.
I'm not convinced that an MVC approach is necessary for web apps, but I do like the code separation. Off-topic, that was a nice article in php|a, sweatje. I'm looking forward to the conclusion. |
|
Back to top |
|
Justin Smarty Regular
Joined: 07 May 2003 Posts: 38 Location: Vilnius, Lithuania
|
Posted: Fri May 16, 2003 4:22 am Post subject: |
|
|
Well, I use my own DB abstraction class
* connect( array $config )
* disconnect()
* getAll( string $sql [, array $params] )
* getRow( string $sql )
* getOne( string $sql [, string $fieldName] )
* getCol( string $sql )
* insert( string $table, array $array )
* replace( string $table, array $array )
* update( string $table, array $array [, string $condition] )
* delete( string $table [, string $condition] )
* countQuery( [string $table [, string $extraParams]] );
* affectedRows()
* lastID()
.. and I'm realy happy It works fast, It's small.. _________________ http://www.baubas.net |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Fri May 16, 2003 8:28 am Post subject: |
|
|
Justin wrote: | Well, I use my own DB abstraction class
* connect( array $config )
* disconnect()
* getAll( string $sql [, array $params] )
* getRow( string $sql )
* getOne( string $sql [, string $fieldName] )
* getCol( string $sql )
* insert( string $table, array $array )
* replace( string $table, array $array )
* update( string $table, array $array [, string $condition] )
* delete( string $table [, string $condition] )
* countQuery( [string $table [, string $extraParams]] );
* affectedRows()
* lastID()
.. and I'm realy happy It works fast, It's small.. |
Me too. And my abstraction layer looks quite the same |
|
Back to top |
|
Wom.bat Smarty Pro
Joined: 24 Apr 2003 Posts: 107 Location: Munich, Germany
|
Posted: Fri May 16, 2003 1:36 pm Post subject: |
|
|
in my opinion, web development isn't the very best field of operation for the MVC model... I just don't like it
for PHP applications, it's mostly enough to cleanly seperate your presentation and application logic along with a good structure and well designed classes etc... |
|
Back to top |
|
Justin Smarty Regular
Joined: 07 May 2003 Posts: 38 Location: Vilnius, Lithuania
|
Posted: Fri May 16, 2003 1:39 pm Post subject: |
|
|
andre wrote: |
Me too. And my abstraction layer looks quite the same |
huh I've implemented this from scratch _________________ http://www.baubas.net |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Mon May 19, 2003 6:48 am Post subject: |
|
|
Justin wrote: | andre wrote: |
Me too. And my abstraction layer looks quite the same |
huh I've implemented this from scratch |
Me too |
|
Back to top |
|
andreas Smarty Pro
Joined: 22 Apr 2003 Posts: 106
|
Posted: Tue May 20, 2003 9:55 pm Post subject: |
|
|
boots wrote: | @Toma: Well, Pear is still a mess on Windows. |
I've read somewhere(http://pear.php.net/weeklynews.php/en/20030413.html) that PEAR-Integration with Windows will be much better with PHP version 4.3.2!
Perhaps you should have a look again when it is released
________
Dodge Venom specifications
Last edited by andreas on Fri Feb 04, 2011 9:01 am; edited 2 times in total |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue May 20, 2003 10:01 pm Post subject: |
|
|
Quote: | Perhaps you should have a look again when it is released |
I certainly intend to check it out. On the other hand, I've been "waiting" for Pear to work on windows for a long time. To be fair, I stopped waiting awhile ago, but I still check in on the project now and then. I really do want it to be better, but as things stand, I doesn't look like it will ever be a big part of my trick-bag.
I suspect Pear will get "good" around PHP 5.1 or somewhere after that.
Still, I'd like to see more examples of solutions that use Smarty in conjunction with Pear projects. |
|
Back to top |
|
koide Smarty Rookie
Joined: 06 May 2003 Posts: 5
|
Posted: Wed May 21, 2003 1:21 am Post subject: What's the big problem about MVC + Web? |
|
|
Wom.bat wrote: | in my opinion, web development isn't the very best field of operation for the MVC model... I just don't like it
for PHP applications |
I agree that it was thought for 'Desktop' GUI's and there is where it really shines, but it's very nice to help structuring your code and concern separations. I just started developing a Eocene+Smarty+ADODb app and it's amazing the ease of development and maintenance compared to what i used to do in only Smarty+ADODb. The performance impact is not too big, and it really _really_ helps to implement a well-thought design. I agree you can perfectly do this without the help of actually implementing (or using an existing) MVC framework, but isn't this all about ease of development, easy maintenance and quick deployment times? Remember you can still program in Assembly and get the same functionality.
Of course you can argue that I didn't (or don't) know how to "cleanly seperate your presentation and application logic along with a good structure and well designed classes etc...", but my point is exactly that, now I can do it easily. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed May 21, 2003 1:33 am Post subject: |
|
|
Quote: | I agree you can perfectly do this without the help of actually implementing (or using an existing) MVC framework, but isn't this all about ease of development, easy maintenance and quick deployment times? Remember you can still program in Assembly and get the same functionality. |
The problem with using MVC is two-fold:
1) It requires extensive use of language features that PHP simply does not support very well. PHP5 will be a much better match for class intensive frameworks.
2) MVC solves a problem (fairly elegantly) that simply does not exist for nearly every type of current web-based application: the co-ordination of data among disperate items in an interactive environment. (The key here is the "interactive")
Further, unless you actually have experience developing with an object framework as abstracted as MVC, you are likely going to make some critical implementation errors. Even if you are good at it, it is not unreasonable that your class hierarchies become increasingly obtuse leading to far more difficult maintenance. Using existing frameworks helps, but sometimes they are just more rope to hang yourself with.
Not to say that MVC isn't useful or can't lead to pleasant designs. Its just that for web apps, much simpler frameworks can achieve the same end results while being faster and easier to maintain. The point here is that if you use overkill on a problem, your solution will be much more complicated (and therefore more brittle) than it need be.
Also, I'm not saying that MVC's approach is incorrect--its all about the layers. I am saying that for web apps, MVC is likely too much of a good thing.
Last edited by boots on Wed May 21, 2003 1:51 am; edited 1 time in total |
|
Back to top |
|
koide Smarty Rookie
Joined: 06 May 2003 Posts: 5
|
Posted: Wed May 21, 2003 1:51 am Post subject: MVC & web |
|
|
boots wrote: |
1) It requires extensive use of language features that PHP simply does not support very well. PHP5 will be a much better match for class intensive frameworks.
|
I agree, but with PHP 4.2 and upwards it's _doable_, not easy, but you can at least make it work. And that's a problem with PHP, not with the model.
boots wrote: |
Using existing frameworks helps, but sometimes they are just more rope to hang yourself with.
|
Yes, in fact I have tried Phrame, phpMVC, a few other I don't remember and finally I stumbled upon Eocene. It's lightweight, easy to work with, easy to modify to your needs (I adapted Smarty and ADODb to it in less than a day of work), and easy to understand. You should check it out if you still haven't.
boots wrote: |
Not to say that MVC isn't useful or can't lead to pleasant designs. Its just that for web apps, much simpler frameworks can achieve the same end results while being faster and easier to maintain.
|
As I said above, I've looked at a lot of frameworks to do my coding with, and still have to find a great one. Eocene is the closest to great I've found so far. It's based on MVC, but that's not a reason by itself not to use it. I agree with the cons for MVC and web, but do you have a better alternative? Please share! |
|
Back to top |
|
eadz Smarty Regular
Joined: 30 Apr 2003 Posts: 61 Location: Auckland, New Zealand
|
Posted: Wed May 21, 2003 3:24 am Post subject: |
|
|
ez_sql.php - it's lightweight, free, fast, and perfect for smarty |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed May 21, 2003 5:51 pm Post subject: |
|
|
@eadz: I looked at ez and it is cute. Small and does very little (which I like) but does offer some convenience functions.
Not extremely flexible and since it is driverless, it looks like you can't have access multiple db types without extending the classes (since every db type uses the same class name). I'm not sure I'd use this long-term, but I do like its output styles Has anyone patched this to be Smarty aware and use templates internally instead of embedded HTML? |
|
Back to top |
|
|
|
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 vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|