PHP Object Oriented Web Application?

Since there will be only one User for every request and thus for every run of your program, this would be a case to make "User" a Singleton class as described here: php.net/manual/en/language.oop5.patterns... That would provide the one way for other classes to refer to the current user without the chance of accessing the wrong instance since there is only one DISCLAIMER: Yes, I know that Singeltons are often used at the wrong places for the wrong purpose and some people tend to blame this problem on the pattern instead of the people who misused it for some smelly code. This however is a perfectly good use case for the Singelton pattern.

Since there will be only one User for every request and thus for every run of your program, this would be a case to make "User" a Singleton class as described here: php.net/manual/en/language.oop5.patterns... That would provide the one way for other classes to refer to the current user without the chance of accessing the wrong instance since there is only one. DISCLAIMER: Yes, I know that Singeltons are often used at the wrong places for the wrong purpose and some people tend to blame this problem on the pattern instead of the people who misused it for some smelly code. This however is a perfectly good use case for the Singelton pattern.

I have edited my post to show some code. Let's assume I made the User class a singleton class...do I pass the instance of User to each of the other instances of the classes? If not, could you show some code to explain please.

– Sev May 26 '10 at 8:23 If you User class is a singleton, you access it's only existing instance with User::singleton(), assuming the method names from the PHP manual page. That method will then always return the exact same instance of User and no other way of accessing it must be allowed. – Techpriester May 26 '10 at 8:44.

Globalizing" something by putting it in a session variable or cookie for the sole purpose of globalizing it is a very bad habit to get into, and it leads to tightly coupled libraries that rely on an arbitrary variable being set outside the class. Session variables in general are good to stay away from for other reasons, too. The best way to get a variable into any class is to pass it as an argument.Do you have a method in your Layout class that renders (outputs) it?

You may want to add a $data argument to that method that takes an associative array of data usable in the layout.

I'd personally use a registry class (Singleton) and register the user there for the Layout to access. That way, you only need to pass an instance of the registry to the Layout. The User class is not integral to the Layout's construction - since it should only be concerned with the Layout, so I wouldn't pass that in the constructor.

Another method would be to use a Controller to orchestrate these interactions between Views and Models. Whenever a new Controller is created, buffer it's output. Then, at render time, unbuffer the contents and assign them to properties (or a property array) of the view, which can then render them.

You probably don't need an actual Model class to be passed to the View/Layout - just it's output.

Use a registry pattern. No need to make it a singleton, everyone is throwing that word around. Include "layout.

Php" include "user. Php" if(userAuthSuccess) { $data'currentUser' = new User($_POST'username'); } $data'nav' = new nav('home'); $homelayout = new Layout( $data ); Now $homelayout can access $data (which contains all the variables you put into it) via the data array.

– Sev May 26 '10 at 22:29 also, I would need to create a new User from every page – Sev May 26 '10 at 22:30 its one extra line of code. Also makes it more readable for other people reading your code. – Galen May 27 '10 at 1:24.

PHP-GTK 2 is now one step closer to a final release. Entire PHP-GTK team for making this release possible! Which team or individual can build the best application in 24 hours.

Skill and stamina. Here in the PHP-GTK community know that the best applications are written with PHP-GTK. Enter PHP-GTK applications into the contest.

Hits at the community site. Provides useful tips and code samples for PHP-GTK, be sure to stop by. Christian created a map which tells you where PHP-GTK 2 developers and users are located.

Freenode and add yourself! Includes a package manager written entirely in PHP-GTK 2! Has adopted PHP-GTK 2 at such a level; we hope this trend continues!

The Chinese translation of the PHP-GTK 2 manual has now begun. Help in making a faster release! Quicker and painless.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions