require_once at symfony

后端 未结 4 1498
一向
一向 2021-01-07 10:46

I\'m making now things with php + Symfony2 framework, and I have the following code:

require_once(\"one_file.php\");
require_once(\"another_file.php\");
         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 11:50

    If these classes reside inside bundle then you could use as below: Suppose your bundle name is AcmeDemoBundle. Place this file inside Acme/DemoBundle/Model/

      //one_file.php
       namespace Acme/DemoBundle/Model;
       class one_file {
       ...........
       }
    

    To use this file inside your controller or any other file:

    Here for Acme/DemoBundle/Controller/UserController.php

       namespace Acme/DemoBundle/Controller   
       use Acme/DemoBundle/Model/one_file
        class UserController {
        public $one_file=new one_file();
        }
    

    In php 5.3 onwards, namespaces has been introduced. You should probably look at namespaces and its uses in php documentation

提交回复
热议问题