PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 21, 2022

[FIXED] require_once at symfony

 January 21, 2022     composer-php, php, symfony     No comments   

Issue

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");

... and so on.

The problem is, how to "Symfonyze" these uncomfortable require sentences, and after, how to include these files in the Symfony2 package?

We've thought about two possibilities:

  1. Include the file at /vendors directory of symfony, or
  2. Include each class as a service.

Solution

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



Answered By - sonam
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing