I'm using Doctrine ORM in my PHP project.
In one of my queries I'm using the 'COS' (cosine) and 'SIN' (sine) functions, in order to make this possible on Doctrine I have to add this to my entitymanager configuration:
$config->addCustomNumericFunction('COS', 'DoctrineExtensions\Query\Mysql\cos');
$config->addCustomNumericFunction('SIN', 'DoctrineExtensions\Query\Mysql\sin');
This works fine when I run it on my local PC + server.
But once I put the project on the online webserver I'm facing with these errors:
Fatal error: Class 'DoctrineExtensions\Query\Mysql\cos' not found in /home/USER/domains/USER.com/public_html/MYDIRECTORY/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php on line 3418
Fatal error: Class 'DoctrineExtensions\Query\Mysql\sin' not found in /home/USER/domains/USER.com/public_html/MYDIRECTORY/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php on line 3418
It's looking in the 'vendor\doctrine' directory instead of the 'vendor\beberlei\DoctrineExtensions' directory.
My composer contains:
"beberlei/DoctrineExtensions": "dev-master"
And the vendor autoloader contains:
'DoctrineExtensions\\' => array($vendorDir . '/beberlei/DoctrineExtensions/src')
Can anyone explain this to me... I tried adding a classloader, but still the same problem.
Localhost is working fine...
When adding sine and cosine functions to the entitymanager config I used:
$config->addCustomNumericFunction('COS', 'DoctrineExtensions\Query\Mysql\cos');
$config->addCustomNumericFunction('SIN', 'DoctrineExtensions\Query\Mysql\sin');
The solution above is working on a local PC + server.
When moving the project files to the webserver the above config won't work.
You have to change the first letter of the last word in the DoctrineExtensions namespace to uppercase, like this:
$config->addCustomNumericFunction('COS', 'DoctrineExtensions\Query\Mysql\Cos');
$config->addCustomNumericFunction('SIN', 'DoctrineExtensions\Query\Mysql\Sin');
Basically cos becomes Cos and sin becomes Sin .
Now it works on the online webserver. Finally got it working!
Related
I'm completly new to Symfony and tried the following guide: https://github.com/thecodingmachine/symfony-vuejs ... but without docker (I have a simple webspace, I can't use docker there).
Now I'm stuck right in the beginning, when calling composer install in the app root. I get the following message:
In EnvVarProcessor.php line 131:
Environment variable not found: "DATABASE_URL".
Well, that sounds easy, I have to setup an enviroment variable ... but I'm not using docker and I don't want to set up a temporarly variable in the shell. Few seconds of google helped me, that I can use .env for my problem like descriped here: https://symfony.com/doc/current/configuration.html#configuration-based-on-environment-variables
In the example project is already a .env file, so I extendet it by DATABASE_URL. But suddenly it is not taking that variable.
I'm working on a macbook with a simple apache/php setup without forther configuration.
What am I missing?
I have set up PHPUnit on Windows to do unit testing within my Moodle application. My php version is 7.2.10 and the version of PHPUnit is 7.5.
I was able to successfully install composer and then PEAR and PHPUnit.
I was then able to initialise the Moodle PHPUnit test environment by running:
php ../phpunit/cli/init.php
This successfully set up the test environment and ran all of the unit tests in the application.
The problem I have is when I attempt to run a single test, using e.g.
vendor\bin\phpunit /mod/quiz/tests/event_test.php
This gives me the following error:
Class '/mod/quiz/tests/event_test.php' could not be found in ''.
The solution to a similar looking problem, PHPUnit error - Class could not be found, does not solve the issue. I had to modify the solution since the StandardTestSuiteLoader class has changed - I tried making all comparisons to realpath($suiteClassFile) case insensitive but this has not worked.
I'm not overly familiar with running phpunit against a file path as opposed to a class name, but is this expecting an absolute path?
/mod/quiz/tests/event_test.php
Is probably trying to be loaded from the root directory. Either try dropping the leading /, or supply the full windows file path, including C:
I've developed a small project on a machine, using CakePHP 3.0, and I need it to run on another machine. I've tried to install it on several other machines.
If I run the composer to install the CakePHP 3.0, then I copy my stuff to overwrite it, the project works. I've tried this on two machines and had no problem so far. If I don't run the composer, and just copy the stuff to the target machine, it gives me the following error. I've tried this on 3 machines, and every machine gives me this:
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
I've copied the whole project to this server to test.
I told you this because I thought it has something to do with my problem. The point is that I have to run this on a machine that is not mine, and I can't install composer on it. The /public_html/vendor/cakephp/cakephp/src/I18n/ has files related to internationalization and localization, but my project will never be translated, so a workaround to make the project ignore those files would be enough to solve my problem.
The following code is an excerpt from the (...)/I18n/I18n.php that might be relevant:
<?php
namespace Cake\I18n;
use Aura\Intl\FormatterLocator;
use Aura\Intl\PackageLocator;
use Aura\Intl\TranslatorFactory;
use Cake\I18n\Formatter\IcuFormatter;
use Cake\I18n\Formatter\SprintfFormatter;
use Locale;
class I18n {
// lots of code here
public static function defaultLocale() {
if (static::$_defaultLocale === null) {
static::$_defaultLocale = Locale::getDefault() ?: 'en_US';
// the line above is the Line 229
}
return static::$_defaultLocale;
}
// many code here too
}
I've checked that another file also tries to access this Locale class, but I don't know if there are other files trying to access it as well. Many files from everywhere inside the project tries to access methods from I18n.php. I need it running but I can't figure out how to make it run.
Any help will be greatly appreciated.
As I just found out, prior to CakePHP 3.0, the installation must be done by composer, as stated in the 3.0 migration guide:
CakePHP should be installed with Composer
Since CakePHP can no longer easily be installed via PEAR, or in a shared
directory, those options are no longer supported. Instead you should use
Composer to install CakePHP into your application.
So it won't run on regular free web hosting services.
Environment:Amazon EC2. Ubuntu x64. (GD library installed)
I'm recently using phpChart for graph and report in laravel framework.
I'm stuck at the beginning stage.
Here's what I've done.
1.Unzip the contents in phpChart_Lite to /var/www/app/libraries/phpChart.
2.Edit composer.json and add :
"autoload": {
"classmap": [
...
"app/libraries"
]
},
3.run:composer dump-autoload
4.modify conf.php in phpChart_Lite
define('SCRIPTPATH',app_path().'/libraries/phpChart_Lite/');
Here's my test page code:
<?php
require_once(app_path()."/libraries/phpChart_Lite/conf.php");
$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart');
$pc->draw();
?>
ps.my app_path() is verified by "echo app_path()" and it is "/var/www/app".
Here's my error message:
Unknown: Failed opening required '/var/www/public//var/www/app/libraries/phpChart_Lite//conf.php'
(include_path='/var/www/vendor/phpseclib/phpseclib/phpseclib:.:/usr/share/php:/usr/share/pear')
After a lot of try-and-error, I somehow found the root cause, I guess.
There are actually two main issue there. And here's my solution.
1.For my issue explained in the very first post.
In the conf.php file in phpChart_Lite folder. The SCRIPTPATH is somehow prefixed with /var/www/public.
However, in my apache2.conf file states the directory to be /var/www. Regardless this prefix, I use a absolute path for SCRIPTPATH. The following modification works for me:
define('SCRIPTPATH','../app/libraries/phpChart_Lite/');
The error was gone. But the second issue appears, that is the chart doesn't show up.
Open the Chrome Developer Tool(press F12). On the 'Console' tab, I found error 404 for loading phpChar_Lite/js. One of the error messages as following:
http://myip/app/libraries/phpChart_Lite/js/highlighter/styles/zenburn.css
As the design of Laravel, only public folder can be access by external request.
So I got second issue. And here's my solution.(not a secured method)
2.Move the phpChart_Lite to public folder. Modify the code of test page:
include_once(public_path()."/phpChart_Lite/conf.php");
Modify the conf.php in public/phpChart_Lite:
define('SCRIPTPATH','phpChart_Lite/');
Everything's just fine now.
If you consider phpChart is too complicate to configure with, you might want to try pChart2.0.
It doesn't require much setting. But the graph is terribly ugly.
I prefer phpChart for it's graph and function calls, though the setting is a little complicated and not laravel friendly.
I am getting Class 'Splash\\SiteBundle\\Util\\Resize' not found when running my app on prod. This does not happen on dev.
Here is the code from the error:
$resize = new \Splash\SiteBundle\Util\Resize($this->getAbsolutePath());
I have a file called Splash\SiteBundle\Util\Resize.php with this namespace
namespace Splash\SiteBundle\Util;
Class Resize{ ... }
Any thoughts?
So the quick fix is to add this include dirname(__FILE__) . "/../Util/Resize.php"
I am not sure why my production machine would need the include while my dev machine works fine without it. Using Symfony2 and the autoloader I have never needed to include a file. Not sure whats goin on but this get me past it for now
One of the possible thing that could lead this to happen could ne not cleared cache
php app/console cache:clear -e prod
Another stupid thought could be that production has merge conflicts within that file and PHP doesn't see the class compiled.
I love when its the little things. My util folder was not capitalized. I changed this and it works now. I'm surprised my dev machine did not fail w this error.