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.
Related
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?
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'
...
I am building my website with Yii2 advanced template. The URL is rewritten into
localhost:9001/projectyii/page/index/#/demo
(page is controller, index is action, /#/demo is just a route for AngularJS on frontend)
Everything works fine on my localhost. When I upload it into my server, whenever if I hit the URL has prefix example.com/projectyii/, it will throw the following exception
ReflectionException
Class yii\web\urlManager does not exist
1. in /home/scott/public_html/projectyii/vendor/yiisoft/yii2/di/Container.php at line 415
406407408409410411412413414415416417418419420421422423424 * #return array the dependencies of the specified class.
*/
protected function getDependencies($class)
{
if (isset($this->_reflections[$class])) {
return [$this->_reflections[$class], $this->_dependencies[$class]];
}
$dependencies = [];
$reflection = new ReflectionClass($class); // error here
I notice that there are some other websites that have been running on same server already (they are all using Yii 1.1.13) and they have been working without problem, such as
example.com/project1/
example.com/project2/
...
it's just failed just this new site in Yii2.
The setting is under of components on /frontend/config/main.php is
'urlManager' => [
'class' => 'yii\web\urlManager',
'baseUrl' => $baseUrl,
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
]
The error told that it could not find the urlManager class, but the class does exist, the namespace is fine because I DO NOT modify anything on the vendors folder where contains that urlManager class.
I do not understand what I am missing here. Any help is appreciated! Thanks
Linux like other unix systems are case sensitive you should use:
'class' => 'yii\web\UrlManager', instead of urlManager
I've succesfully created and uploaded advanced template on my shared host.
As next step, I must run the yii migrate.
But I cannot because I've not the console access.
What could you suggest to me?
Please note that
I cannot change the host, because it's not a decision of mine
I cannot access the server using SSH
I've already tried something like PHPShell, but I got permissione denied when trying to runyii migrate --interactive=0
I tried also this: added an actionMigrateUp to frontend/controllers/siteController.php
public function actionMigrateUp()
{
// https://github.com/yiisoft/yii2/issues/1764#issuecomment-42436905
$oldApp = \Yii::$app;
new \yii\console\Application([
'id' => 'Command runner',
'basePath' => '#app',
'components' => [
'db' => $oldApp->db,
],
]);
\Yii::$app->runAction('migrate/up', ['migrationPath' => '#console/migrations/', 'interactive' => false]);
\Yii::$app = $oldApp;
}
But when I visit /frontend/web/index.php?r=site/migrateUp I got a 404
exception 'yii\base\InvalidRouteException' with message 'Unable to
resolve the request: site/migrateUp' in
C:\xampp\htdocs\www\vendor\yiisoft\yii2\base\Controller.php:122
The action that you have created is not accesible with
/frontend/web/index.php?r=site/migrateUp
but with
/frontend/web/index.php?r=site/migrate-up
Otherwise everything should be fine.
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.