Unable to find template in Symfony 3 - php

I know that there are a lot of subject like that however I didn't find the solution
I have this issue
Unable to find template "CoreBundle:index.html.twig" (looked into: /var/www/html/MyProject/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).
This is the architecture
This is my controller
<?php
namespace CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class DefaultController extends Controller
{
/**
* #Route("/", name="index")
*/
public function indexAction(Request $request)
{
return $this->render('CoreBundle:index.html.twig');
}
/**
* #Route("/ma-personnalite", name="ma-personnalite")
*/
public function mapersonnaliteAction(Request $request)
{
return $this->render('CoreBundle:ma_personnalite.html.twig');
}
/**
* #Route("/cv", name="cv")
*/
public function cvAction(Request $request)
{
return $this->render('CoreBundle:cv.html.twig');
}
/**
* #Route("/scolaires", name="scolaires")
*/
public function scolairesAction(Request $request)
{
return $this->render('CoreBundle:scolaires.html.twig');
}
/**
* #Route("/extra-scolaires", name="extra-scolaires")
*/
public function extrascolairesAction(Request $request)
{
return $this->render('CoreBundle:extra_scolaires.html.twig');
}
/**
* #Route("/contact", name="contact")
*/
public function contactAction(Request $request)
{
return $this->render('CoreBundle:contact.html.twig');
}
}
This is the config.yml
#app/config/routing.yml
core:
resource: "#CoreBundle/Controller/"
type: annotation
prefix: /
Thanks for your time

According to the Symfony 3 Docs it's better to use slashes and to not use "Bundle" word.
So, we have as example:
return $this->render('#BloggerBlog/Default/index.html.twig');

try to change this:
return $this->render('CoreBundle:index.html.twig');
to this:
return $this->render('CoreBundle::index.html.twig');
The difference is to use :: instead of :

This helped me in my case:
#Core/index.html.twig

Related

Laravel 5.4 – error while creating facade

This is how I create helper (App\Helpers\Settings.php)
namespace App\Helpers;
use Illuminate\Database\Eloquent\Model;
class Settings {
protected $settings = [];
public function __construct() {
$this->settings['AppName'] = 'Test';
}
/**
* Fetch all values
*
* #return mixed
*/
public function getAll () {
return $this->settings;
}
}
Creating facade (App\Helpers\Facades\SettingsFacade.php)
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Settings extends Facade {
protected static function getFacadeAccessor() {
return 'Settings';
}
}
Creating Service Provider (App\Providers\SettingsServiceProvider.php)
namespace App\Providers;
use Illuminate\Support\Facades\App;
use Illuminate\Support\ServiceProvider;
class SettingsServiceProvider extends ServiceProvider {
/**
* Bootstrap the application events.
*
* #return void
*/
public function boot() {
}
/**
* Register the service provider.
*
* #return void
*/
public function register() {
App::bind( 'Settings', function () {
return new \App\Helpers\Settings;
});
} */
}
Registering provider (App\Providers\SettingsServiceProvider::class)
Creating alias: 'Settings' => App\Facades\Settings::class
Running composer dump-autoload
Trying to use facade Settings::getAll();
Getting error Class 'App\Http\Controllers\Settings' not found
Can’t figure out why I cannot create facade and getting that error
try this one.
App\Helpers\Settings.php
namespace App\Helpers;
use Illuminate\Database\Eloquent\Model;
class Settings {
protected $settings = [];
public function __construct() {
$this->settings['AppName'] = 'Test';
}
/**
* Fetch all values
*
* #return mixed
*/
public function getAll () {
return $this->settings;
}
}
App/Http/Controllers/XyzController.php
use Facades\App\Settings;
class XyzController extends Controller
{
public function showView()
{
return Settings::getAll();
}
}
web.php
Route::get('/','XyzController#showView');
use Facades\App\Helpers\Settings;
Route::get('/direct',function() {
return Settings::getAll();
});
use laravel Real time facades

The controller for URI is not callable symfony2

i get this error
[enter image description here][1]
i have in my project 2 bundles the first one is working just fine the seconde is called DemandeBundle i get the error
namespace DemandeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class DefaultController extends Controller
{
/**
* #return \Symfony\Component\HttpFoundation\Response
* #route("/homedemande",name="homedemande")
*/
public function indexAction()
{
return $this->render('#DemandeBundle/Default/index.html.twig');
}
/**
* #return \Symfony\Component\HttpFoundation\Response
* #route("/demande_create",name="demande_create")
*/
public function demande_create()
{
return $this->render('#DemandeBundle/Default/demande_create.html.twig');
}
}
i suspect i have a problem in routing.yml
demande_create:
path: /demande_create
defaults: { _controller: DemandeBundle:Default:demande_create}
your action needs to be suffixed with Action keyword to be callable that is probably the first issue here
function definition should be something like
public function demande_createAction()

Laravel - FatalThrowableError Class 'App\Http\Controllers\Input' not found

I'm new to Laravel so I'm not familiar with errors in the framework .I'm trying to get the user to make a post but I'm getting the above error .Could you please tell where I'm going wrong ?Thank you
This is my HomeController class:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Http\Response
*/
public function index(Request $r)
{
if(Input::has('status-text'))
{
$text = e(Input::get('status-text'));
$userStatus = new Status();
$userStatus->status_text = $text;
$userStatus->save();
Flash::success('Your status has been posted');
return redirect(route('home'));
}
return view('home');
}
}
And this is my web.php class :
<?php
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::any('/home', ['as'=> 'home','uses' =>'HomeController#index']);
Don't use Input::get(), use $r->get() as you're injecting the request as a dependency to the index method already, and Input:: is merely a alias to access the underlaying Request.

how to reuse symfony route

I want to reuse a route in symfony as I used in Slim framework.
for example: in Slim I could define groups and then I would put the actions inside the group:
$app->group("example",..{
$app->get("/staff"...);
$app->get("test");
$aap->group("books",..{
$app->get("/"..);
$app->delete("/{id}")
})
});
And to access to the action test the url would be like: "domain/example/test", and to access staff: "domain/example/staff";
and to access book would be like: "domain/example/book/";
can I do this in symfony without having to go to every controller and put it manually.
The symfony documentation provide an example on how defines a prefix for all action routes:
/**
* #Route("/example")
*/
class ExampleController extends Controller
{
/**
* #Route("/staff")
*/
public function staffAction()
{
}
/**
* #Route("/test")
*/
public function testAction()
{
}
}
/**
* #Route("/example/books")
*/
class BookController extends Controller
{
/**
* #Route("/")
*/
public function indexAction()
{
}
/**
* #Route("/{id}")
* #Method({"DELETE"})
*/
public function deleteAction($id)
{
}
}

Best Practices on namespaces : on Symfony, difference of perfs when using (sub)namespaces?

I'm building an API and I would ask something about using namespaces on a Symfony2 controller.
Is there a real difference doing :
<?php
namespace My\APIBundle\Controller;
use FOS\RestBundle\Controller\Annotations\View,
FOS\RestBundle\Controller\Annotations\Post,
FOS\RestBundle\Controller\Annotations\Get;
use [...]
class MyRestController extends Controller {
[...]
/**
* #View()
* #Get()
*/
public function getAction(Thing $thing) {
return $thing;
}
/**
* #View()
* #Post()
*/
public function postAction() {
}
or doing
<?php
namespace My\APIBundle\Controller;
use FOS\RestBundle\Controller\Annotations as Rest;
use [...]
class MyRestController extends Controller {
[...]
/**
* #Rest\View()
* #Rest\Get()
*/
public function getAction(Thing $thing) {
return $thing;
}
/**
* #Rest\View()
* #Rest\Post()
*/
public function postAction() {
}
Would the alias load everything in the given namespace, losing perfs ?
Or will it load only annoted classes, unitary ?

Categories