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

Wednesday, February 9, 2022

[FIXED] How to include a custom php file?

 February 09, 2022     php, symfony     No comments   

Issue

I have added a new directory and a new file into src/AppBundle. So the path is: src/AppBundle/Helper/Helper.php

The path of my controller is as usual src/AppBundle/Controller/MyController.php.

I would now like to include the file Helper.php to my Controller. How can I do this?


Solution

One possibility, assuming your AppBundle/Controller/MyController in Symfony 2.8 it looks something like this:

namespace AppBundle\Controller\MyController

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class MyController extends Controller
{
...
}

and your Helper class includes public function getSomeHelp()

you can then define a service in services.yml:

services
    app.helper:
        class: 'AppBundle\Helper\Helper'

and in your MyController:

public function someFunctionAction() {
    ...
    $helper = $this->get('app.helper');
    $something = $helper->getSomeHelp();


Answered By - geoB
  • 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