Resolves a bug in the brophp of the model class with a namespace
The first project was completed, though he was not satisfied with the project, but anyway, it ended.
Because you have a small base and don't want to do projects with purely process-oriented and OOP, the first project is going to use a framework to do
So in the current study brophp code, on the basis of brophp made a "self" framework
Say it is their own, in fact, just understand the brophp, control this brophp rewrite it again.
This bug was discovered by accident on the project.
I called D (' user ', ' admin ') at the front desk to verify the user's rights and then update the user data in another controller using D (' user ') common.class.php
This makes a mistake. The hint cannot be repeated to define the Usermodel class, which is a problem with a class that calls 2 identical names
As we name the class, we can't use Memcache,mysqli.
When the project, time tight, did not dare to think, just consider the next more easy solution: The two classes are renamed plus the project name.
Project finished, fell two days, this evening again think of this problem, think carefully, suddenly think of php5.3 new namespace is to solve such problems and increased
Turned down the manual and researched the new thing, and it really solved the problem.
Header plus namespace definition when generating a model compilation file
Like Home usermodel.php.
-
- namespace home;
- Class Usermodel extends \dpdo {
- }
Admin's usermodel.php
-
- namespace admin;
- Class Usermodel extends \dpdo {
- }
Note that the \ in front of Dpdo, because other files do not have a namespace defined, belong to the global space "if no namespace is defined, all classes and functions are defined in the global space, as before the introduction of the namespace concept in PHP. Prefix the name with
\Indicates that the name is a name in the global space, even if the name is in a different namespace. ”
Modify the D method so that the model is instantiated in the following form
- $h = new Home\usermodel ();
- $a = new Admin\usermodel ();
This solves the problem of repeating the calling class.
The specific code will not be sent, interested in children's shoes can try
In fact, the simplest method is to instantiate the time of unification, such as all with D (' user ', ' admin '), will not appear this problem
But it's a matter of evading, not solving.