3
votes

create class Tools\MainBundle\Controller\Sm_Image_HandlerController

<?php

namespace Tools\MainBundle\Controller;
class Sm_Image_HandlerController{

    public function test($param) {
        return $param;
    }
}

other class :

<?php

namespace FoodBundle\Controller;

use FoodBundle\Entity\FoodMaterialMapping;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use FoodBundle\Entity\Food;
use Symfony\Component\Validator\Constraints\NotBlank;
use Tools\MainBundle\Controller\Sm_Image_HandlerController;

/**
 * Food controller.
 *
 */
class FoodController extends Controller {
public function indexAction() {
$param="sample";
$sm=new Sm_Image_HandlerController();
$sample=$sm->test($param);
return new \Symfony\Component\HttpFoundation\Response(sample);
}

if run function indexAction in class foodController return error

Attempted to load class "Sm_Image_HandlerController" from namespace "Tools\MainBundle\Controller". Did you forget a "use" statement for another namespace?

src/FoodBundle/Controller/FoodController.php at line 23

<?php
 public function createAction(Request $request) {
        $param = "sample";
        $sm = new Sm_Image_HandlerController();
        $sample = $sm->test($param);
        return new \Symfony\Component\HttpFoundation\Response(sample);
    }
1
please use camel case for controller name and try again: Sm_Image_HandlerController to SmImageHandlerControllerM Gholami
rename file and classM Gholami

1 Answers

2
votes

you must use CamelCase naming for class and file name in symfony rename your controller and its file like this

class SmImageHandlerController{

    public function test($param) {
        return $param;
    }
}