Home > Backend Development > PHP Tutorial > 如何自动require加载配置?

如何自动require加载配置?

WBOY
Release: 2016-06-06 20:31:10
Original
1292 people have browsed it

我每次写控制器时候,总是加载它才能运行(MEDOO数据类)
写法是

<code><br>    class ListController{ 

        function index() { 

            require('Config/Conn.php'); 
            $db=$data->select("mini_content",[
                 "id",
                 "title" ,
                 "content"
           ]
        } 

    } 

</code>
Copy after login
Copy after login

我把它放外面不起作用了

<code>require('Config/Conn.php'); 
class ListController{ 

    function index() { 
        $db=$data->select("mini_content",[
             "id",
             "title" ,
             "content"
       ]
    } 

} 

</code>
Copy after login
Copy after login

将来以后还要写控制器,一个一个写require('Config/Conn.php'); 很麻烦
例子:

<code><br>     function index() { 

        require('Config/Conn.php'); 
    } 
     function xxx() { 

        require('Config/Conn.php'); 
    } 
     function xxx2() { 

        require('Config/Conn.php'); 
    } 

</code>
Copy after login
Copy after login

有什么办法 自定函数自动认require('Config/Conn.php'); 呢?

回复内容:

我每次写控制器时候,总是加载它才能运行(MEDOO数据类)
写法是

<code><br>    class ListController{ 

        function index() { 

            require('Config/Conn.php'); 
            $db=$data->select("mini_content",[
                 "id",
                 "title" ,
                 "content"
           ]
        } 

    } 

</code>
Copy after login
Copy after login

我把它放外面不起作用了

<code>require('Config/Conn.php'); 
class ListController{ 

    function index() { 
        $db=$data->select("mini_content",[
             "id",
             "title" ,
             "content"
       ]
    } 

} 

</code>
Copy after login
Copy after login

将来以后还要写控制器,一个一个写require('Config/Conn.php'); 很麻烦
例子:

<code><br>     function index() { 

        require('Config/Conn.php'); 
    } 
     function xxx() { 

        require('Config/Conn.php'); 
    } 
     function xxx2() { 

        require('Config/Conn.php'); 
    } 

</code>
Copy after login
Copy after login

有什么办法 自定函数自动认require('Config/Conn.php'); 呢?

google composer

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template