Symfony2 project on a distant server problems - php

I'm now looking about 2 weeks for running a website (very simple, just for testing the first steps like a HelloWorld) on a hosting, but still nothing.
I'm new on symfony and it could be that my error is "normal" but I cannot find my answer on the internet. So my problem is the following:
I developed a website on my PC with symfony2. It has just a little html/css page which I would like to see on the server. Locally, everything works fine: no errors, nothing. When I upload the entire project (after clearing cache) via FTP on the hosting (http://www.nexlink.ch/) I've got the following error:
Oops! An Error Occurred
The server returned a "500 Internal Server Error".
Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
and the logger tells me the following things:
INFO - Matched route "HelloTheWorld" (parameters: "_controller": "fcbgNewsBundle:news:index", "name": "bolet", "_route": "HelloTheWorld")
CRITICAL - Uncaught PHP Exception InvalidArgumentException: "Unable to find controller "fcbgNewsBundle:news" - class "fcbg\newsBundle\Controller\newsController" does not exist." at /mnt/sites/fc-beroche.ch/web/fusio/app/cache/dev/classes.php line 2333
Context: {"exception":"Object(InvalidArgumentException)"}
What did I do wrong?
Here my controller:
<?php
namespace fcbg\newsBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class newsController extends Controller
{
public function indexAction($name)
{
echo $name;
$page = $this->render(
'base.html.twig',
array(
'content' => 'fcbgNewsBundle:Default:index.html.twig',
'titrePage' => $name,
'navigation' => array(
array(
'href' => 'http://www.youpi.com',
'titre' => 'menu1'
),
array(
'href' => 'http://www.youpi.com',
'titre' => 'menu2'
),
array(
'href' => 'http://www.youpi.com',
'titre' => 'menu3'
),
),
'css' => 'fcbgNewsBundle:Default:basicStyle.css'
)
);
return $page;
}
}

The problem is probably here:
INFO - Matched route "HelloTheWorld" (parameters: "_controller": "fcbgNewsBundle:news:index", "name": "bolet", "_route": "HelloTheWorld")
As you can see this:
fcbgNewsBundle:news:index
It is expected as
fcbg\NewsBundle\newsController -> indexAction
But you have:
namespace fcbg\newsBundle\Controller;
^
n character with lover-case. Use upper-case and you should also use upper-cased characters at the start of your controller names (NewsController instead of newsController) to avoid these problems in the future.

Related

Symfony3 returns "internal server error 500" only in prod

we are getting this 500 error but only in prod environment. This app works fine in DEV/QA env
Even in prod this app works fine until you send a form to edit some data in data base. Then, when
debuggin I realized that this error occurs here:
return new JsonResponse(
array(
'message' => $message,
'form' => $this->renderView(
$template,
array(
'cv' => $cv,
$formName => $form->createView(),
)
),
'view' => $view
),
$code
);
apparently the path for the template in $view not exist. But it makes no sense because it does exists, even the app calls this template in other context and just works fine.
My english is not good so I hope you can understand me. Thank you!
EDIT: Symfony and server error logs has been already checked, but found nothing about this error.

Failed to load resource: the server responded with a status of 404 (Not Found) - LARAVEL 8

I have a problem with my routes on the server and using laravel 8, with a version of php 8.0.6
When developing locally I have no problem with the routes, everything is normal, but when uploading the project to the server (to which I do not have access but someone else uploads the changes from the repository) it throws me the following error in some views...
Error 404
In my code I have the routes declared as follows in the routes/web.php file...
Route::get('/home', 'PagesController#home');
Each view has a function that comes from the controller...
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PhpParser\Node\Expr\FuncCall;
class PagesController extends Controller
{
public function home()
{
$page_title = 'Dashboard';
return view('pages.dashboard', compact('page_title'));
}
}
On the other hand, each route can be accessed through a menu aside
// Aside menu
return [
'items' => [
// Dashboard
[
'title' => 'Dashboard',
'root' => true,
'icon' => 'media/svg/icons/Design/Layers.svg', // or can be 'flaticon-home' or any flaticon-*
'page' => '/home',
'new-tab' => false,
]
]
]
I tried :
correct writing to avoid mistakes
change "/" in each affected path
note: they told me the server was in strict mode

Laravel Lumen PHPUnit always returns 404

I'm using Laravel Lumen 8.0. And building the Unit Tests for the endpoints. But got pretty fast stuck.
<?php
class ExampleTest extends TestCase
{
public function testShouldReturnAllUsers(){
$parameters = [
'first_name' => 'First_name',
'last_name' => 'TestUser',
'locale' => 'nl',
'email' => 'First_name#test'.rand(0,11111111111).'com',
'password' => 'asdasfasfgasgrresdfsgrwe'
];
//$this->json('post', 'users', $parameters)
// ->seeStatusCode(200);
$this->get('/users/b11d4d56-00ff-4af8-84c2-f1a14c8724c7');
$this->seeStatusCode(200);
}
}
There was 1 failure:
1) ExampleTest::testShouldReturnAllUsers
Expected status code 200 but received 404.
Failed asserting that 200 is identical to 404.
/Users/Sites/App/Services/users/vendor/illuminate/testing/TestResponse.php:186
/Users/Sites/App/Services/users/vendor/laravel/lumen-framework/src/Testing/Concerns/MakesHttpRequests.php:426
/Users/Sites/App/Services/users/vendor/laravel/lumen-framework/src/Testing/Concerns/MakesHttpRequests.php:437
/Users/Sites/App/Services/users/tests/ExampleTest.php:19
Going through endless questions here on SO. The answer has always been te same, check your APP_URL in the .env file and ensure that this is accessible and the it represents the actual URL of the application.
I check this 100 times and it is the actual URL and accessing this in the browser works.
How to move forward? Can I see where the request was pointed to?

Trying to get property on a non object Yii 1.1.15

I try to change Css file for CGridView widget, in my config/main.php:
'components' => array(
'widgetFactory' => array(
'widgets' => array(
'CGridView' => array(
'cssFile' => Yii::app()->request->baseUrl . '/css/gridview.css',
),
),
),
...
And I get warning:
Trying to get property on a non object /path_to_project/protected/config/main.php on line 79
How I can suppress this warning, and why I getting it, in when I using it in view files it all works.
P.S. Yes I can set display_errors ini set to false and message will dissapearm but I want get clearly with it. Thanks!
The reason for the warning is that the CHttpRequest object Yii::app()->request has not been instantiated yet.
From the API page for CApplication:
CApplication will undergo the following lifecycles when processing a
user request:
load application configuration;
set up error handling;
load static application components;
onBeginRequest: preprocess the user request;
processRequest: process the user request;
onEndRequest: postprocess the user request;
Starting from lifecycle 3, if a PHP error or an uncaught exception occurs, the application will switch to its error handling logic and jump to step 6 afterwards.
Your error is happening at the first step. As such, Yii's error handling has not been setup yet. The only option is to suppress this warning using the # operator:
'cssFile' => #Yii::app()->request->baseUrl . '/css/gridview.css',
HOWEVER
This is a terrible idea, since you are essentially hiding the error instead of fixing it.
If your views are being displayed correctly (no css errors), you can omit the Yii::app()->request->baseUrl and just use:
'cssFile' => '/css/gridview.css'
If you are experiencing errors, you can create a class in your components folder that extends CWidgetFactory and set any variables that depend on other components here e.g
class MyWidgetFactory extends CWidgetFactory {
public function init() {
parent::init();
$this->widgets['CGridView']['cssFile'] = Yii::app()->request->baseUrl.'css/gridview.css';
}
}
You will need to adjust your components to use this file:
'components' => array(
'widgetFactory' => array(
'class' => 'MyWidgetFactory'
...

No adapter set exception when setting multiple connections in li3

I am attempting to set-up multiple connections in my li3 project but when I do I get an uncaught exception. I set my connections in the app/confi/bootstrap/connections.php file which is then loaded in by the bootstrap.php file. Here is what I have for my connections:
Connections::add('default', array(
'development' => array(
'type' => 'MongoDb',
'host' => 'localhost',
'database' => 'web_app'
),
'test' => array(
'type' => 'MongoDb',
'host' => 'localhost',
'database' => 'test_web_app'
)
)
);
When I have it set like this and try to browse to my project I get this error:
Fatal error: Uncaught exception 'lithium\core\ConfigException' with message 'No adapter set for configuration in class `lithium\data\Connections`.' in /var/www/site/libraries/lithium/core/Adaptable.php:233
However when I just have a single default connection set-up it works fine. Has anyone else ran into this issue?
--UPDATE--
I went looking through the stack trace from the exception and found the issue is caused by a filter I set-up in my file app/config/bootstrap/user.php which is then loaded by bootstrap.php
Here is what my user.php file looks like:
use app\models\Users;
use lithium\security\Password;
Users::applyFilter('save', function($self, $params, $chain) {
if ($params['data']) {
$params['entity']->set($params['data']);
$params['data'] = array();
}
if (!$params['entity']->exists()) {
$params['entity']->password = Password::hash($params['entity']->password);
}
return $chain->next($self, $params, $chain);
});
According to the stack trace the error is coming from line 21 of this file. The only thing on line 21 is }); so I am still not certain why this is causing an error.
It would appear I was mislead by Li3's Simple Authentication user tutorial. In their tutorial it has you create a user.php file in the bootstrap directory and has the filter logic in this file (Exactly what I had). However it seems this is not the best way to go about it, especially when using multiple connections as it will throw the exception above. I have moved the filter logic to my Users model file in app/models/Users.php and no longer get the exception. This is the same type of setup that Gavin Davies uses in his Li3 Authentication example.

Categories