Rasmus Lerdorf, creator of the PHP langauge, has a new tutorial on his site today that looks at the creation of a "no-framework PHP MVC framework" using PHP5, the Yahoo! User Interface Library, and JSON.
He steps through the entire process of working up the "non-framework" - the goals of the project, why to go with the MVC approach for the structure, and, of course, the code.
That arose the PHP's own MVC Pattern discussion in PHP Community.But i have my own view.Here is my response in one of most famous PHP community:
一场精彩的CMMI论战 Here
quoted from o6z's post: 文档最忌讳繁琐无比,事无巨细的都要说明,如果是这样我直接去看代码好了。实际上多数人都默认文档的抽象程度比代码级别高,看文档比看代码省事。但是如果你的文档过于细节化,那么你的代码很难做到同步于文档。这将是一个巨大的威胁。很多人抱怨要看一堆没文档的代码,但是他们很少真的看到过合适的文档。实际上文档的作用应该是让阅读者快速找的代码的位置,而不是用文字说明代码的作用,那些应该是单元测试的事情。
人员的流动带来的最大问题,实际是知识的流失。文档可以固定下一部分的知识,但是如果文档的抽象层次不够,这些知识并不能很容易的被掌握,那么这些就是无用功。
AutoAssist is an auto completion web widget that written in pure JavaScript. It can help enhance the accessibility of existing website, let the users to work effective and feel comfortable. AutoAssist Javascript only and is built upon prototype and rico. Its main features are :
* improve the User Experience * Don't require an Ajax experience * pretty managed JavaScript, easy to understand and customize * works well on Mozilla/FireFox, IE and Opera * have a nice solution for fast user typing, reduce a lot of corresponding server loading (20% - 80% *)
The code for the screenshot is very simple :
var foo = function() { var tt = new AutoAssist("t", {setRequestOptions: function() { var pars = "name=" + this.txtBox.value; return { url: "/country.php", parameters: pars }; }}); } Event.observe(window, "load", foo);
You can find a ten minutes tutorial for AutoAssist explaining in details how to use this script to create an auto-complete list based on country data.
By the way,script.aculo.us also has it's impelmention:http://demo.script.aculo.us/ajax/autocompleter
See DFlying's finding: Yep,No Block Scope concept in JavaScript.Only the global and function Scope.You can use "var" to declare a global variable and use "var" agian to declare a homonymous variable in a function.In the function ,the second one works.But there is no Block scope. Check the codes below,it's a demo for "NO BLOCK SCOPE" function test(o){var i = 0; // i is defined throughout functionif(typeof o == "object"){var j = 0; // j is defined everywhere, not just blockfor(var k = 0; k < 10; k++){// k is defined everywhere, not just loopdocument.write(k);
}document.write(k); // k is still defined: prints 10}document.write(j); // j is defined, but may not be initialized}
But,You still need to care javascript's FUNCTION SCOPE.Also see code snippet: var scope = "global";
function f(){alert(scope); // Displays "undefined", not "global"var scope = "local"; // Variable initialized here, but defined everywherealert(scope); // Displays "local"}f(); Right,thought you alert(scope) first and then define a new functin scope variable scope.However,once you define a function scope vriable,it will hide the global variable in the function body,whatever the definition order.
Venkman is a Javascript Debugger as a FireFox extenstion.It's at least powerful than IE's default script debugger(not Visual InterDev's).You can watch varaiable,set breakpoint and use "step over" "step into" "step out" "continue" buttons to debug your niffy javascript codes. It's ease to use.And tutorial is HERE:http://www.svendtofte.com/code/learning_venkman/index.php
POJO used by Hibernate needs to implement hashCode() and equals() method.That's a kind of stuffy work and will be done many many times during development.Some IDEs support automatical generation feature such as IDEA.Eclipse famous plug-in--MyElipse also suppots but it's not free of charge. I think nearly all JAVAers know Apache Commons open source project.We can use Commons lib to generate hashCode() and equals() method.I wanna tell you that there is also a plugin for Eclipse called Commons4E which help you generate hasCode() and equals(). It also can generate toString() and compareTo() method.That's a smart plugin.Enjoy it.Link
Hibernate object relational mapping offers both lazy and non-lazy modes of object initialization. Non-lazy initialization retrieves an object and all of its related objects at load time. This can result in hundreds if not thousands of select statements when retrieving one entity. The problem is compounded when bi-directional relationships are used, often causing entire databases to be loaded during the initial request. Of course one could tediously examine each object relationship and manually remove those most costly, but in the end, we may be losing the ease of use benefit sought in using the ORM tool.
The obvious solution is to employ the lazy loading mechanism provided by hibernate. This initialization strategy only loads an object's one-to-many and many-to-many relationships when these fields are accessed. The scenario is practically transparent to the developer and a minimum amount of database requests are made, resulting in major performance gains. One drawback to this technique is that lazy loading requires the Hibernate session to remain open while the data object is in use. This causes a major problem when trying to abstract the persistence layer via the Data Access Object pattern. In order to fully abstract the persistence mechanism, all database logic, including opening and closing sessions, must not be performed in the application layer. Most often, this logic is concealed behind the DAO implementation classes which implement interface stubs. The quick and dirty solution is to forget the DAO pattern and include database connection logic in the application layer. This works for small applications but in large systems this can prove to be a major design flaw, hindering application extensibility.
Being Lazy in the Web Layer
Fortunately for us, the Spring Framework has developed an out of box web solution for using the DAO pattern in combination with Hibernate lazy loading. For anyone not familiar with using the Spring Framework in combination with Hibernate, I will not go into the details here, but I encourage you to read Hibernate Data Access with the Spring Framework. In the case of a web application, Spring comes with both the OpenSessionInViewFilter and the OpenSessionInViewInterceptor. One can use either one interchangeably as both serve the same function. The only difference between the two is the interceptor runs within the Spring container and is configured within the web application context while the Filter runs in front of Spring and is configured within the web.xml. Regardless of which one is used, they both open the hibernate session during the request binding this session to the current thread. Once bound to the thread, the open hibernate session can transparently be used within the DAO implementation classes. The session will remain open for the view allowing lazy access the database value objects. Once the view logic is complete, the hibernate session is closed either in the Filter doFilter method or the Interceptor postHandle method. Below is an example of the configuration of each component:
Implementing the Hibernate DAO's to use the open session is simple. In fact, if you are already using the Spring Framework to implement your Hibernate DAO's, most likely you will not have to change a thing. The DAO's must access Hibernate through the convenient HibernateTemplate utility, which makes database access a piece of cake. Below is an example DAO.
Even outside the view, the Spring Framework makes it easy to use lazy load initialization, through the AOP interceptor HibernateInterceptor. The hibernate interceptor transparently intercepts calls to any business object configured in the Spring application context, opening a hibernate session before the call, and closing the session afterward. Let's run through a quick example. Suppose we have an interface BusinessObject:
publicinterface BusinessObject {publicvoid doSomethingThatInvolvesDaos();
}</pre><p><font size="2">The class BusinessObjectImpl implements BusinessObject:</font></p>
<p />
<pre>public class BusinessObjectImpl implements BusinessObject {publicvoid doSomethingThatInvolvesDaos(){// lots of logic that calls// DAO classes Which access // data objects lazily}}
Through some configurations in the Spring application context, we can instruct the HibernateInterceptor to intercept calls to the BusinessObjectImpl allowing it's methods to lazily access data objects. Take a look at the fragment below:
When the businessObject bean is referenced, the HibernateInterceptor opens a hibernate session and passes the call onto the BusinessObjectImpl. When the BusinessObjectImpl has finished executing, the HibernateInterceptor transparently closes the session. The application code has no knowledge of any persistence logic, yet it is still able to lazily access data objects.
Being Lazy in your Unit Tests
Last but not least, we'll need the ability to test our lazy application from J-Unit. This is easily done by overriding the setUp and tearDown methods of the TestCase class. I prefer to keep this code in a convenient abstract TestCase class for all of my tests to extend.
public abstract class MyLazyTestCase extends TestCase {private SessionFactory sessionFactory;
private Session session;
publicvoid setUp()throwsException{
super.setUp();
SessionFactory sessionFactory = (SessionFactory) getBean(\"sessionFactory"<img alt=";)" src="http://www.dflying.net/plugins/smileys/icons/default/wink_smile.gif" />;
session = SessionFactoryUtils.getSession(sessionFactory, true);
Session s = sessionFactory.openSession();
TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(s));
}protectedObject getBean(String beanName){//Code to get objects from Spring application context}publicvoid tearDown()throwsException{
super.tearDown();
SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
Session s = holder.getSession();
s.flush();
TransactionSynchronizationManager.unbindResource(sessionFactory);
SessionFactoryUtils.closeSessionIfNecessary(s, sessionFactory);
}}