I am currently experimenting with the Phalcon Framework, and running into some complications when I attempt to save content into the Mongo Database. I can correctly setup the MySQL database without issues. Whenever I send the simple request through I get a 500 Internal server error (checking devTools). I have setup everything accordingly as the documentation specifies.
This is my simple index.php bootstrap Mongo initialisation along with the collection manager:
// Setting Mongo Connection
$di->set('mongo', function() {
$mongo = new Mongo();
return $mongo->selectDb("phalcon");
}, true);
// Setting up the collection Manager
$di->set('collectionManager', function(){
return new Phalcon\Mvc\Collection\Manager();
}, true);
This is my controller handling the request:
public function createAction() {
$user = new User();
$user->firstname = "Test ACC";
$user->lastname = "tester";
$user->password = "password";
$user->email = "testing#example.com";
if($user->create() == false) {
echo 'Failed to insert into the database' . "\n";
foreach($user->getMessages as $message) {
echo $message . "\n";
}
} else {
echo 'Happy Days, it worked';
}
}
And finally my simple User class:
class User extends \Phalcon\Mvc\Collection {
public $firstname;
public $lastname;
public $email;
public $password;
public $created_at = date('Y-m-d H:i:s');
}
Much appreciated for everyones input/suggestions.
i think it's because your installation of Mongo is not valid.
try printing phpinfo() and check if mongo is loaded at all, if not - install it, add to ini files (if you use cli, don't forget to add to cli ini too) and reach the moment, when mongo is fully loaded.
try mongo w/o phalcon. any simple connection/insertation. you can see here: Fatal Error - 'Mongo' class not found that there are problems with apache module version for some people. Try reinstalling different mongo version.
if you can print this out:
echo Phalcon\Version::get();
there should be no problems with phalcon instalation
to validate mongo installation, try any of examples from php.net:
http://www.php.net/manual/en/mongo.tutorial.php
A little bit late, but for anyone else facing this issue, it would be a good idea to try and connect to mongo (run "mongo" in your terminal) to ensure that mongo is setup correctly in your dev environment.
Also, I usually find in this sort of situation, that adding a collection to a database in mongo and then testing the CRUD process with a simple read helps move things along. If all is well at this stage, then you know your app is able to connect and you can proceed to writes, and so on.
This looks useful.
Related
I have a basic controller action:
public function createAction() {
$this->view->disable();
$formData = $this->request->getJsonRawBody();
$user = new Users();
$user->first_name = $formData->first_name;
$user->last_name = $formData->last_name;
$user->email_address = $formData->email_address;
$user->password = $formData->password;
// this prints to my debug log.
$result = $user->save();
AppLogger::$logger->debug(print_r($result, true)); // this does not print.
AppLogger::$logger->debug("oh boy #2"); // this does not print either.
// which seems to tell me that the line above it is problematic,
// but there is no error output from `phalcon serve`
echo Json::encode($result);
}
The closest thing I see to an error is this: PHP/Phalcon Error: Closed without sending a request; it was probably just an unused speculative preconnection. This is appearing in the output of phalcon serve.
I'm running phalcon serve in VSCode on Windows.
I fixed this by wrapping $result = $user->save(); in a try/catch, then I was able to see the exception.
It seems that this exception is not automatically displayed in the terminal output...
Had the same issue when a user tries to log out, restarted my server(laravel inbuilt server)and it worked like a charm.
If you're cloning a Laravel project, make sure your .env file is created. They have sensitive information and may be kept inside .gitignore.
Try running npm install and npm run dev worked for me
So I am starting a docker symfony 4 project and i am trying to use a controller. I already created the database that i need by running
doctrine:database:create
and it work and created my database so the connection is good. however, when i run this code below. I get that error. I a little confuse on why mysql doesnt connect. anyone know?
Ive tried change mysql versions, composing it down and updating different mysql root and password and is not connecting.
class HospitalAdminController extends AbstractController
{
/**
* #Route("/admin/hospital/new")
*/
public function new(EntityManagerInterface $em)
{
$hospital = new Hospital();
$hospital->setName('Example Hospital')
->setPhone(8175831483)
->setAddress('123 Avenue');
$em->persist($hospital);
$em->flush();
return new Response(sprintf(
'Hiya! New Hospital id: #%d phone:%s address%s',
$hospital->getId(),
$hospital->getPhone(),
$hospital->getAddress()
));
}
}
just trying to run my controller and do a proof of concept.
I’ve read the documentation on https://cloud.google.com/appengine/docs/php/symfony-hello-world and I managed to deploy the Hello World app, but when I try with my symfony app I have his error:
InvalidArgumentException in XmlFileLoader.php line 259: Unable to parse file "(…) DependencyInjection/../Resources/config\web.xml".
In app.yaml I set the env variables:
env_variables:
GCS_BUCKET_NAME: "pinterpandaibucket"
CACHE_DIR: "gs://pinterpandaibucket/symfony/cache"
LOG_DIR: "gs://pinterpandaibucket/symfony/log"
And I overloaded the AppKernel.php functions:
public function __construct($environment = null, $debug = null)
{
// determine the environment / debug configuration based on whether or not this is running
// in App Engine's Dev App Server, or in production
if (is_null($debug)) {
$debug = !Environment::onAppEngine();
}
if (is_null($environment)) {
$environment = $debug ? 'dev' : 'prod';
}
parent::__construct($environment, $debug);
// Symfony console requires timezone to be set manually.
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
// Enable optimistic caching for GCS.
$options = ['gs' => ['enable_optimsitic_cache' => true]];
stream_context_set_default($options);
$this->gcsBucketName = getenv('GCS_BUCKET_NAME');
...
public function getCacheDir()
{
if ($this->gcsBucketName) {
return getenv('CACHE_DIR');
}
return parent::getCacheDir();
}
public function getLogDir()
{
if ($this->gcsBucketName) {
return getenv('LOG_DIR');
}
return parent::getLogDir();
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
?>
The functions which write to the file system are redirected to the bucket.
Could you help me to find what modifications are missing in my app.
I hope this topic will help someone else because the Google cloud documentation isn't very up to date.
Thank you in advance and sorry if I don’t speak English very well I’m a French IT student.
Augustin
I have spent many an hours on this horrible bug, and what I found was this issue happens on the Dev AppServer, but not in production. I believe it is an issue with the implementation of the xml.so php extension in that environment.
This is fixed in the symfony starter app with the method fixXmlFileLoaderBug, which gets called in web/app.php. So ensure this is being called, and you should be good to go.
If you're experiencing this bug in Production, or you continue to experience this issue even after calling this function, please let us know by filing an issue on github.
I'm trying to implement the SimpleSAMLphp authentication tool in cakePHP.
I wrote a SamlAuthenticate component in app\Controller\Component\Auth which looks like this:
class SamlAuthenticate extends Component {
[...]
public function authenticate(CakeRequest $request, CakeResponse $response) {
$source = null;
$as = null;
if ($this->Session->check('Saml.source')) {
$source = $this->Session->read('Saml.source');
}
if ($source) {
require_once($this->settings['path'] . DS . 'lib' . DS . '_autoload.php');
$as = new SimpleSAML_Auth_Simple($source);
if(!$as->isAuthenticated()) {
$as->login();
} else {
return $as->getAttributes();
}
}
return false;
}
}
But I'm always getting an loop between the identity provider and my cake application.
I was wondering, if my server is the problem or I did something wrong with the configuration of the identity provider, so I wrote a simple test script and it worked without a problem:
require_once('/../simplesamlphp/lib/_autoload.php');
$as = new SimpleSAML_Auth_Simple('facebook');
$as->requireAuth();
echo $as->isAuthenticated();
So, something in cakePHP breaks the authentication process. The SimpleSAMLAuthToken is set correctly (I can see that through the SimpleSAMLphp admin panel), but $as->isAuthenticated() always returns false.
I also tried https://github.com/bvidulich/CakePHP-simpleSAMLphp-Plugin with the same result.
maybe you are in a session conflict.
Take a look on the LostState info of the simpleSAMLphp documentation.
A fast workaround to see if that is your problem:
Configure the simplesamlphp to save the session on memcache. You will need to install a memcache server, the memcache php driver (remember to restart your apache after install ir) and then edit the config/config.php file of simpleSAMLphp and set
'store.type' => 'memcache',
Check that the simpleSAMLphp can write a session using the cookie extension of firefox. (Take a look on the session/cookie params of the config/config.php file.
I'd like Symfony to log the Doctrine SQL queries that one of my tasks executes to a log file, much like the web debug toolbar does for non-cli code. Is this possible?
Symfony version: 1.4.12
Doctrine version: 1.2.4
Here's some example code for a task. I would like the SELECT query to be logged in a similar way to how it would be if it was called from an action.
class exampleTask extends sfBaseTask
{
protected function configure()
{
parent::configure();
$this->namespace = 'test';
$this->name = 'example';
}
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$users = Doctrine_Core::getTable('SfGuardUser')
->createQuery('s')
->select('s.first_name')
->execute();
foreach($users as $user) {
print $user->getFirstName()."\n";
}
}
}
Try using the global task option --trace (shortcut -t). Like:
./symfony --trace namespace:task
It logs database queries the moment they are executed.
Don't forget to enable logging in the settings.yml of the application you're running the task in.
So if you're running the task in the dev environment of the backend you would edit apps/backend/config/settings.yml:
dev:
.settings:
logging_enabled: true
Note that this also logs stack traces of exception which might also be very helpful if you need to debug your tasks.
If you turn logging on all queries should be logged to your application log in the log directory. To do this set logging_enabled to true in your settings.yml.
You can then tail -f on the logfile and see what's going on.
The following link contains a nice tutorial on how to enable logging of the Doctrine queries. (translated from the original portuguese to english)
http://translate.google.com/translate?js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&sl=pt&tl=en&u=http%3A%2F%2Fwww.michaelpaul.com.br%2Flog-queries-doctrine.html&act=url