Resolves a bug in brophp that repeatedly calls the model class with a namespace

Source: Internet
Author: User
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.
    1. namespace home;
    2. Class Usermodel extends \dpdo {
    3. }

Admin's usermodel.php
    1. namespace admin;
    2. Class Usermodel extends \dpdo {
    3. }

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
    1. $h = new Home\usermodel ();
    2. $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.


  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.