I'm creating a Cakephp(3.5.14) plugin, it is working fine with the below given routes
plugins/timesheet/config/routes.php
Router::plugin(
'Timesheet', ['path' => '/timesheets'], function (RouteBuilder $routes) {
$routes->setExtensions(['json']);
$routes->connect('/', ['controller' => 'Timesheets', 'action' => 'index']);
$routes->connect('/edit', ['controller' => 'Timesheets', 'action' => 'edit']);
$routes->connect('/add', ['controller' => 'Timesheets', 'action' => 'add']);
$routes->fallbacks(DashedRoute::class);
as per the documentation this I added in
project src/config/routes.php
$routes->scope('/backend', function ($routes) {
$routes->loadPlugin('Timesheet');
});
BUt somehow, it's not working.
My URL: www.xxx.com/backend/timesheets
Error: BackendController could not be found.
In the case you tried to access a plugin controller make sure you added it to your composer file or you use the autoload option for the plugin.
Error: Create the class BackendController below in file: src\Controller\BackendController.php
use App\Controller\AppController;
class BackendController extends AppController
{
}
Stack Trace:
⟩ Cake\Http\ControllerFactory->missingController
CORE\src\Http\ControllerFactory.php, line 38
⟩ Cake\Http\ControllerFactory->create
CORE\src\Http\ActionDispatcher.php, line 90
⟩ Cake\Http\ActionDispatcher->dispatch
CORE\src\Http\BaseApplication.php, line 108
⟩ Cake\Http\BaseApplication->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
CORE\src\Routing\Middleware\RoutingMiddleware.php, line 104
⟩ Cake\Routing\Middleware\RoutingMiddleware->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
CORE\src\Routing\Middleware\AssetMiddleware.php, line 88
⟩ Cake\Routing\Middleware\AssetMiddleware->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
CORE\src\Error\Middleware\ErrorHandlerMiddleware.php, line 98
⟩ Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
ROOT\vendor\cakephp\debug_kit\src\Middleware\DebugKitMiddleware.php, line 52
⟩ DebugKit\Middleware\DebugKitMiddleware->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
CORE\src\Http\Runner.php, line 51
⟩ Cake\Http\Runner->run
CORE\src\Http\Server.php, line 81
⟩ Cake\Http\Server->run
ROOT\webroot\index.php, line 40
Thanks in advance.
Check the other routes that are connected in your application, there's most likely a route connected earlier that catches the request, probably one that looks for something like /:controller/:action (either explicitly, or as fallback routes), hence it uses the backend part as the controller.
You can easily get a list of all connected routes via the routes shell:
bin/cake routes
Related
I have the following code:
$coretable = new coretable;
$coretableKeyArray = [];
$coretableKeyArray["Internal_key"] = $coretableInput["Internal_key"];
if(is_array($coretableKeyArray)){
log::info("recognized as array");
}
$lastInsert = $coretable->firstOrCreate($coretableKeyArray, $coretableInput);
The array for argument 1 of firstOrCreate() looks like this:
[2020-02-27 07:30:50] local.INFO: array (
'Internal_key' => 'TESTKEY_4',
)
the is_array() also returns true on $coretableKeyArray
However, when doing the call to firstOrCreate() here:
$lastInsert = $coretable->firstOrCreate($coretableKeyArray, $coretableInput);
I get this error:
(1/1) TypeError
Argument 1 passed to Illuminate\Database\Eloquent\Builder::firstOrCreate() must be of the type array, int given, called in E:\aether-backend\vendor\illuminate\support\Traits\ForwardsCalls.php on line 23
in Builder.php line 415
at Builder->firstOrCreate(4, array('coretable_id' => 4, 'description_itc' => 'EXTENSION_ITC_4'))in ForwardsCalls.php line 23
at Model->forwardCallTo(object(Builder), 'firstOrCreate', array(4, array('coretable_id' => 4, 'description_itc' => 'EXTENSION_ITC_4')))in Model.php line 1618
at Model->__call('firstOrCreate', array(4, array('coretable_id' => 4, 'description_itc' => 'EXTENSION_ITC_4')))in modelInteractions.php line 128
Why is that? Also, why does the log of the error show me:
Builder->firstOrCreate(4, array('coretable_id' => 4, 'description_itc' => 'EXTENSION_ITC_4'))
Why is the first argument "4" here? What does it represent? Because it cant represent the value of the first argument of the call to firstOrCreate() because that was an entirely different one...
EDIT:
Here is the full errorstack, as requested per comment:
(1/1) TypeError
Argument 1 passed to Illuminate\Database\Eloquent\Builder::firstOrCreate() must be of the type array, int given, called in E:\aether-backend\vendor\illuminate\support\Traits\ForwardsCalls.php on line 23
in Builder.php line 415
at Builder->firstOrCreate(4, array('coretable_id' => 4, 'description_itc' => 'EXTENSION_ITC_4'))in ForwardsCalls.php line 23
at Model->forwardCallTo(object(Builder), 'firstOrCreate', array(4, array('coretable_id' => 4, 'description_itc' => 'EXTENSION_ITC_4')))in Model.php line 1618
at Model->__call('firstOrCreate', array(4, array('coretable_id' => 4, 'description_itc' => 'EXTENSION_ITC_4')))in modelInteractions.php line 127
at modelInteractions->insertModel(array('Internal_key' => 'TESTKEY_4'), array('Internal_key' => 'TESTKEY_4', 'extensiontable_itc' => array('description_itc' => 'EXTENSION_ITC_4'), 'extensiontable_sysops' => array('description_sysops' => 'EXTENSION_SYSOPS_4')), array('extensiontable_itc', 'extensiontable_sysops'))in UserController.php line 100
at UserController->insertDataCreateNewItem(object(Request))
at call_user_func_array(array(object(UserController), 'insertDataCreateNewItem'), array(object(Request)))in BoundMethod.php line 32
at BoundMethod::Illuminate\Container\{closure}()in Util.php line 36
at Util::unwrapIfClosure(object(Closure))in BoundMethod.php line 90
at BoundMethod::callBoundMethod(object(Application), array(object(UserController), 'insertDataCreateNewItem'), object(Closure))in BoundMethod.php line 34
at BoundMethod::call(object(Application), array(object(UserController), 'insertDataCreateNewItem'), array(), null)in Container.php line 590
at Container->call(array(object(UserController), 'insertDataCreateNewItem'), array())in RoutesRequests.php line 376
at Application->callControllerCallable(array(object(UserController), 'insertDataCreateNewItem'), array())in RoutesRequests.php line 342
at Application->callLumenController(object(UserController), 'insertDataCreateNewItem', array(true, array('uses' => 'App\\Http\\Controllers\\UserController#insertDataCreateNewItem', 'middleware' => array('auth')), array()))in RoutesRequests.php line 316
at Application->callControllerAction(array(true, array('uses' => 'App\\Http\\Controllers\\UserController#insertDataCreateNewItem', 'middleware' => array('auth')), array()))in RoutesRequests.php line 278
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\\Http\\Controllers\\UserController#insertDataCreateNewItem', 'middleware' => array('auth')), array()))in RoutesRequests.php line 258
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))in Authenticate.php line 36
at Authenticate->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))in Pipeline.php line 105
at Pipeline->then(object(Closure))in RoutesRequests.php line 413
at Application->sendThroughPipeline(array('App\\Http\\Middleware\\Authenticate'), object(Closure))in RoutesRequests.php line 259
at Application->handleFoundRoute(array(true, array('uses' => 'App\\Http\\Controllers\\UserController#insertDataCreateNewItem', 'middleware' => array('auth')), array()))in RoutesRequests.php line 165
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))in CORS.php line 34
at CORS->handle(object(Request), object(Closure))in Pipeline.php line 171
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request))in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))in Pipeline.php line 105
at Pipeline->then(object(Closure))in RoutesRequests.php line 413
at Application->sendThroughPipeline(array('App\\Http\\Middleware\\CORS'), object(Closure))in RoutesRequests.php line 171
at Application->dispatch(null)in RoutesRequests.php line 108
at Application->run()in index.php line 28
EDIT:
Question can be closed or deleted, the solution to the problem was somewhere else.
Try this:
$lastInsert = $coretable->firstOrCreate((array)$coretableKeyArray, $coretableInput);
If that doesn't work, in case you've overloaded firstOrCreate make sure it doesn't do custom casts within it.
Instead of storing in a variable you can directly put it in the method.
Much cleaner and also readable.
$coretable->firstOrCreate([
'Internal_key' => $coretableInput["Internal_key"]
], $coretableInput);
I'm following this tutorial https://www.youtube.com/watch?v=6Oxfb_HNY0U
to build a small lumen testproject.
I'm currently at 27th minute where you are supposed to insert a record through a post request.
To do this, I'm using RESTClient http://restclient.net/
So, the last day I already did my best to tackle this problem, and thanks to SO I also could at least
in part solve the issue:
What does the second paremeter in "json()" do (Lumen/Laravel)?
However, I still get errors instead of new records.
When sending a post request to
http://localhost:8080/api/articles
I get this error:
(1/1) BadMethodCallException
Method Laravel\Lumen\Http\Request::validate does not exist.
in Macroable.php line 103
at Request->__call('validate', array(array('title' => 'required', 'description' => 'required')))in ArticleController.php line 36
at ArticleController->create(object(Request))
at call_user_func_array(array(object(ArticleController), 'create'), array(object(Request)))in BoundMethod.php line 32
at BoundMethod::Illuminate\Container\{closure}()in Util.php line 34
at Util::unwrapIfClosure(object(Closure))in BoundMethod.php line 90
at BoundMethod::callBoundMethod(object(Application), array(object(ArticleController), 'create'), object(Closure))in BoundMethod.php line 34
at BoundMethod::call(object(Application), array(object(ArticleController), 'create'), array(), null)in Container.php line 590
at Container->call(array(object(ArticleController), 'create'), array())in RoutesRequests.php line 376
at Application->callControllerCallable(array(object(ArticleController), 'create'), array())in RoutesRequests.php line 342
at Application->callLumenController(object(ArticleController), 'create', array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 316
at Application->callControllerAction(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 278
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 263
at Application->handleFoundRoute(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 165
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))in RoutesRequests.php line 416
at Application->sendThroughPipeline(array(), object(Closure))in RoutesRequests.php line 171
at Application->dispatch(null)in RoutesRequests.php line 108
at Application->run()in index.php line 28
Since I'm new to Lumen/Laravel, I find it hard to guess anything from this error.
I don't know if I just mispelled something, didn't pay attention to scope or anything like that.
Now, here is the code which produced this error:
web.php (routes), Article.php (the model, residing in app folder) and ArticleController.php (Controller):
web.php:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$router->get('/', function () use ($router) {
return $router->app->version();
});
// was simply 'api' in tutorial
$router->group(['prefix' => '/api'], function($router){
$router->get('articles', 'ArticleController#showAllArticles');
$router->get('articles/{id}', 'ArticleController#showOneArticle');
$router->post('articles', 'ArticleController#create');
});
ArticleController.php
<?php
namespace App\Http\Controllers;
use App\Article;
use Illuminate\Http\Request;
class ArticleController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
//
}
//
public function showAllArticles(){
return response()->json(Article::get(['title', 'description', 'status'])); // ::get([]) spezifiziert die zu referenzierenden Attribute
// ::all() referenziert alle Attribute einer Tabelle/Relation
}
public function showOneArticle($id){
return response()->json(Article::find($id));
}
public function create(Request $request){
//dd($request); //for debugging whether the request is actually being processed
$validatedData = $request->validate([
'title' => 'required',
'description' => 'required',
]);
//dd($request); //for debugging whether the specified fields are required
//insert record
$article = Article::create($request->all());
return response()->json($article, 201);
}
}
Article.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $fillable = [
'title', 'description', 'status'
];
}
Since the function "create()" in this code is modified compared to the tutorial code (see the answer of ege in the SO question referenced at the top), I tried out the tutorial code as well, where the create() function looks like this:
public function create(Request $request){
$this->validation($request, [
'title' => 'required',
'description' => 'required'
]);
$article = Article::create($request->all());
return response()->json($article, 201);
}
and I get another error, in this case:
(1/1) Error
Call to undefined method App\Http\Controllers\ArticleController::validation()
in ArticleController.php line 41
at ArticleController->create(object(Request))
at call_user_func_array(array(object(ArticleController), 'create'), array(object(Request)))in BoundMethod.php line 32
at BoundMethod::Illuminate\Container\{closure}()in Util.php line 34
at Util::unwrapIfClosure(object(Closure))in BoundMethod.php line 90
at BoundMethod::callBoundMethod(object(Application), array(object(ArticleController), 'create'), object(Closure))in BoundMethod.php line 34
at BoundMethod::call(object(Application), array(object(ArticleController), 'create'), array(), null)in Container.php line 590
at Container->call(array(object(ArticleController), 'create'), array())in RoutesRequests.php line 376
at Application->callControllerCallable(array(object(ArticleController), 'create'), array())in RoutesRequests.php line 342
at Application->callLumenController(object(ArticleController), 'create', array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 316
at Application->callControllerAction(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 278
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 263
at Application->handleFoundRoute(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 165
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))in RoutesRequests.php line 416
at Application->sendThroughPipeline(array(), object(Closure))in RoutesRequests.php line 171
at Application->dispatch(null)in RoutesRequests.php line 108
at Application->run()in index.php line 28
I'm basically having the same problems with understanding the error as with first error.
I've looked up the lumen documentation here:
https://lumen.laravel.com/docs/6.x/validation
And again I wonder if I didn't understand the scope correctly (what does "this" refer to here, what object is it, what methods can I actually call from it?).
For the sake of completeness, a screenshot of the table I'm referencing with the eloquent model "Article":
https://imgur.com/onXEgzg
Overall I'm just pretty clueless and I would be really thankful if someone could "give me a lift" ^^
Looking at your modified example (2nd version here of your create() method), The first line of the error shows the problem:
Call to undefined method App\Http\Controllers\ArticleController::validation()
So something is wrong with this line in your code:
$this->validation() ...
Checking the link to the Lumen docs that you include:
The $this->validate helper which is available in Lumen ...
So there is a validate() helper - but you're using validation().
Do you guys know how to get url with parameters and ? keyword using laravel 5.3?
i want to get variable from URL looks like
http://site.dev/user/direct?TransID=42D215C2&CCDapproval=72159&PnrID=gogo&Token=42D215C&CompanyRef=gogo
My route
Route::group(['prefix' => 'user', 'middleware' => 'auth:user'], function()
{
Route::get('/directpay/{id}', 'DirectController#index');
}
ERROR
Sorry, the page you are looking for could not be found.
1/1
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 766
at Router->findRoute(object(Request)) in Router.php line 621
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 54
How to make it happen Thanks.
change :
Route::get('/directpay/{id}', 'DirectController#index');
to:
Route::get('/direct', 'DirectController#index');
to match this :
http://site.dev/user/direct?TransID=42D215C2&CCDapproval=72159&PnrID=gogo&Token=42D215C&CompanyRef=gogo
you can get your parameters like this :
$PnrID = Input::get('PnrID');
or like this:
$PnrID = request()->get('PnrID');
I remember after composer updating I got this error, but previously it worked perfectly, and in comparing the packages versions I didn't find differences. I used it in this way in template:
{{ include(template_from_string(page.body)) }}
where "page" is entity object from controller. Current versions are:
symfony/symfony v2.8.15
twig/extensions v1.4.1
twig/twig v1.30.0
Also in config.yml:
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes:
- 'AppBundle::Form/form_override.html.twig'
Now there is in vendor/twig/twig/lib/twig/Twig/Extension/StringLoader.php visually correct file, but seems it still not working. Full stacktrace:
[1] Twig_Error_Syntax: Unknown "template_from_string" function.
at n/a
in ProjectDir\src\AppBundle/Resources/views/Page.html.twig line 22
at Twig_ExpressionParser->getFunctionNodeClass('template_from_string', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 374
at Twig_ExpressionParser->getFunctionNode('template_from_string', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 162
at Twig_ExpressionParser->parsePrimaryExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 102
at Twig_ExpressionParser->getPrimary()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 55
at Twig_ExpressionParser->parseExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 520
at Twig_ExpressionParser->parseArguments(true)
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 373
at Twig_ExpressionParser->getFunctionNode('include', '22')
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 162
at Twig_ExpressionParser->parsePrimaryExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 102
at Twig_ExpressionParser->getPrimary()
in ProjectDir\vendor\twig\twig\lib\Twig\ExpressionParser.php line 55
at Twig_ExpressionParser->parseExpression()
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 147
at Twig_Parser->subparse(array(object(Twig_TokenParser_Block), 'decideBlockEnd'), true)
in ProjectDir\vendor\twig\twig\lib\Twig\TokenParser\Block.php line 40
at Twig_TokenParser_Block->parse(object(Twig_Token))
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 190
at Twig_Parser->subparse(null, false)
in ProjectDir\vendor\twig\twig\lib\Twig\Parser.php line 103
at Twig_Parser->parse(object(Twig_TokenStream))
in ProjectDir\app\cache\dev\classes.php line 3415
at Twig_Environment->parse(object(Twig_TokenStream))
in ProjectDir\app\cache\dev\classes.php line 3443
at Twig_Environment->compileSource(object(Twig_Source))
in ProjectDir\app\cache\dev\classes.php line 3291
at Twig_Environment->loadTemplate('AppBundle::Page.html.twig')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php line 126
at Symfony\Bridge\Twig\TwigEngine->load('AppBundle::Page.html.twig')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bridge\Twig\TwigEngine.php line 50
at Symfony\Bridge\Twig\TwigEngine->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\TwigEngine.php line 72
at Symfony\Bundle\TwigBundle\TwigEngine->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\TwigEngine.php line 103
at Symfony\Bundle\TwigBundle\TwigEngine->renderResponse('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'), null)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\Controller.php line 185
at Symfony\Bundle\FrameworkBundle\Controller\Controller->render('AppBundle::Page.html.twig', array('page' => object(Page), 'ads' => array(object(VertBanner), object(VertBanner)), 'slug' => 'direktor'))
in ProjectDir\src\AppBundle\Controller\PageController.php line 35
at AppBundle\Controller\PageController->getPageAction('direktor')
in line
at call_user_func_array(array(object(PageController), 'getPageAction'), array('direktor'))
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 144
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php line 64
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel.php line 69
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
in ProjectDir\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php line 185
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in ProjectDir\web\app_dev.php line 28
at require('ProjectDir\web\app_dev.php')
in ProjectDir\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Resources\config\router_dev.php line 40
You must let the Service Container know about your Twig Extension:
# app/config/services.yml
acme.twig.extension.loader:
class: Twig_Extension_StringLoader
tags:
- { name: 'twig.extension' }
Symfony 4:
# config/services.yml
app.twig.extension.loader:
class: Twig\Extension\StringLoaderExtension
tags:
- { name: 'twig.extension' }
For symfony5 and twig3, the answer from here worked: Symfony 4: Add Twig_Extension_StringLoader
# config/services.yaml
services:
Twig\Extension\StringLoaderExtension:
As this is more easily findable in google, I'll add it here.
I am using Lumen to create a website, and while my controllers, routes, and views are well configured, I get an error when I try to use the redirect function in a controller.
This is the error code :
ReflectionException in Container.php line 736: Class url does not exist
in Container.php line 736
at ReflectionClass->__construct('url') in Container.php line 736
at Container->build('url', array()) in Container.php line 631
at Container->make('url', array()) in Application.php line 203
at Application->make('url') in Redirector.php line 39
at Redirector->to('http://opentracker.local/token/archived', '302', array(), null) in helpers.php line 246
at redirect('http://opentracker.local/token/archived') in TokenController.php line 51
at TokenController->unarchive('clickid')
at call_user_func_array(array(object(TokenController), 'unarchive'), array('clickid')) in Container.php line 507
at Container->call(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 567
at Application->callControllerCallable(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 534
at Application->callLumenController(object(TokenController), 'unarchive', array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 507
at Application->callControllerAction(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 475
at Application->callActionOnArrayBasedRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 460
at Application->handleFoundRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 434
at Application->handleDispatcherResponse(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 367
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 610
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 368
at Application->dispatch(null) in RoutesRequests.php line 313
at Application->run() in index.php line 28
My route is well recognized, (you can see it transformed as it should in the error).
Here is the code that I use in my controller :
public function unarchive($attribute){
Token::query()->find($attribute)->update(['is_archived'=>0]);
return redirect(route('token.archived'));
}
I also uncommented the following from boostrap/app.php :
$app->withFacades();
$app->withEloquent();
Is there a problem using the function redirect() with Lumen ? I tried both redirect(route()) and redirect()->route(), and they gave the same result.
If you are on 5.2 there is an issue open for this.
Lumen - Github Issues - redirect() doesn't work, Lumen 5.2 #315
You can use the Illuminate\Http\RedirectResponse directly if needed. (from workaround link below):
return new RedirectResponse('login');
return RedirectResponse::create('login');
Possible workaround from Github Issue