I am using Symfony 1.2 and I have some issues switching context.
This code was working fine:
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('account', 'prod', false);
$context = sfContext::createInstance($configuration, 'account-prod');
$userToLogin = PcUserPeer::retrieveByEmailAddress("myemail#example.com");
Auth::login($context->getUser(), $userToLogin, false, false);
echo "all done.";
At some point requirements changed and I needed to use the 'public' application before the 'account' one.
Then I changed to:
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
// {{{ new code:
$configuration = ProjectConfiguration::getApplicationConfiguration('public', 'prod', false);
sfContext::createInstance($configuration);
// some code using the public app...
// }}}
$configuration = ProjectConfiguration::getApplicationConfiguration('account', 'prod', false);
$context = sfContext::createInstance($configuration, 'account-prod');
// {{{ new code:
sfContext::switchTo('account-prod');
// }}}
$userToLogin = PcUserPeer::retrieveByEmailAddress("myemail#example.com");
CustomAuth::login($context->getUser(), $userToLogin, false, false);
echo "all done.";
Basically I added a switchTo call.
After the change, the code got broken and the error message is this:
PHP Fatal error: Call to a member function prepare() on a non-object in /var/www/html/myproj/symfony/storage/sfPDOSessionStorage.class.php on line 109
Thanks for your help,
Dan
Symfony is trying to load the session storage object. I suppose there is a problem with your new environment's configuration.
Check
/apps/public/config/factories.yml
Look for "storage" and try to find out how is it different from the other app's configuration.
Hard to know without a backtrace/more info what is triggering the error. It looks like you are using sessions stored in a database, and that a query related to that is failing.
Try setting the third argument to getApplicationConfiguration to true (which will turn debug on) and see if you get more output.
At a guess, it looks like the account app is using PDO session storage, and is failing to connect to the database or something?
Related
So it is not a "My PC" problem. I deployed the app on our test server and the changes still don't get applied. Next step is to dig deeper and see if some identity related configuration was overwritten somewhere.
I've set the `Cookie.SameSite` value to `SameSiteMode.Lax` inside`services.ConfigureApplicationCookie(...)`. Now I'm still getting the cookie with the SameSite value set to strict after I restarted the app and signed in.
services.ConfigureApplicationCookie(...):
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = "sessionCookie";
options.Cookie.HttpOnly = true;
options.Cookie.SameSite = SameSiteMode.Lax;
options.Cookie.MaxAge = TimeSpan.FromHours(5);
options.SlidingExpiration = true;
options.LogoutPath = $"/SignOut";
options.AccessDeniedPath = $"/Account/AccessDenied";
});
Tested in both Chrome and Firefox - same behaviour.
Cookies were cleared and I also restarted everything.
Yes, also my PC.
I can change any other attribute.
I've changed the name, secure and other attributes without fail.
We are using IdenityServer4 with our own implementation of IdentityUser:
services.AddDefaultIdentity<ApplicationUser>()
.AddDefaultUI()
.AddRoles<ApplicationRole>()
.AddEntityFrameworkStores<AppIdentityDbContext>();
The problem was the following line of code which came way before the lines shown in the question:
services.AddCookieConfiguration();
This was an method with return type IServiceCollection, which was written by another developer a few months ago. Because of this "error" I realized how messy our Startup.cs actually is and extracted some configurations into their own methods.
I try to get the service metadata of a sapui5 v2 odata model.
Code:
var oModel = new sap.ui.model.odata.v2.ODataModel(someServiceURL);
var oMetadata = oModel.getServiceMetadata();
This should work according to this page:
https://openui5beta.hana.ondemand.com/docs/guide/6c47b2b39db9404582994070ec3d57a2.html
Anyhow I got "undefined" for oMetadata.
If I change code to:
var oModel = new sap.ui.model.odata.v2.ODataModel({
loadMetadataAsync : false,
serviceUrl : someServiceURL
});
Still oMetadata === undefined
According to SDK documentation metadata should be loaded in sync:
Return the metadata object. Please note that when using the model with
bLoadMetadataAsync = true then this function might return undefined
because the metadata has not been loaded yet. In this case attach to
the metadataLoaded event to get notified when the metadata is
available and then call this function.
What is wrong with my code?
I am using (1.28.11):
<script src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js" ...
I started debugging the UI5 code and detected following line:
this.bLoadMetadataAsync = true;
I started debugging of SAPUI5 code and detected following line (seems to be called each time):
this.bLoadMetadataAsync = true;
Is it a bug? Or is something wrong with my code?
Solution:
The following worked for me in an actual application environment. I guess it not being fired in my fiddle was due to no actual data request being made:
var oModel = new sap.ui.model.odata.v2.ODataModel(<ServiceURL>);
oModel.attachMetadataLoaded(null, function(){
var oMetadata = oModel.getServiceMetadata();
console.log(oMetadata);
},null);
Lead up to the solution:
Ok so I started playing around with this a bit and found the following:
.getServiceMetadata() worked fine with sap.ui.model.odata.ODataModel.
with the sap.ui.model.odata.v2.ODataModel the request for the metadata was sent through the network but somehow .getServiceMetadata() returned undefined.
I tried to sap.ui.model.odata.v2.ODataModel.attachMetadataLoaded() but the event was never fired. (This only applied in the jsbin I used)
I will edit this with any further findings I make. If you have anything that should be included in my findings/testing just tell me.
Edit:
The bLoadMetadataAsync is a parameter you can set on the sap.ui.model.odata.ODataModel. The parameter is not in the API for sap.ui.model.odata.v2.ODataModel anymore. I assume that the async loading has been choosen as default.
Edit:
#user3783327 Reported a bug here: https://github.com/SAP/openui5/issues/564
As sirion already mentioned, the ODataModel has now an API named metadataLoaded which returns a promise accordingly. In the resolve function, we can definitely get the service metadata via getServiceMetadata().
myODataModel.metadataLoaded()
.then(() =>/* Do something with */myODataModel.getServiceMetadata());
Alternatively, we can also make use of ODataMetaModel which can be set on any ManagedObject (including View) and provides several useful accessors related to the service metadata. In order to get the meta model, we need to use the appropriate API from the ODataModel instead of instantiating the model directly:
myODataModel.getMetaModel().loaded()
.then(() =>/* Do something with */myODataModel.getMetaModel()/*...*/);
Documentation: Meta Model for OData V2
I am trying to understand Zend Framework 2 (ZF2). Few days ago I bought the book "Learn ZF2: Learning By Example" by Slavey Karadzhov. Now I am reading it and trying to get some examples working.
I am stuck in page 60. The example shown in the book works well, but the modification I just made does not work... Why? How to fix it?
To get into the same code/situation you would have to:
git clone https://github.com/slaff/learnzf2 .
composer.phar self-update
composer.phar install
git stash
git checkout 'ch-view'
After that You will have the same setup as I do.
Now I have changed the file /module/Debug/view/debug/layout/sidebar.phtml from this:
<h1>Top Line</h1>
<?= $this->content ?>
<h1>Bottom Line</h1>
to this (just added one line at the end):
<h1>Top Line</h1>
<?= $this->content ?>
<h1>Bottom Line</h1>
<p>MVC duration: <?= $this->mvcDuration ?></p>
I would like $this->mvcDuration to be the value of $duration from /module/Debug/Module.php file getMvcDuration method.
I changed the content of method getMvcDuration from this:
public function getMvcDuration(MvcEvent $event)
{
// Here we get the service manager
$serviceManager = $event->getApplication()->getServiceManager();
// Get the already created instance of our timer service
$timer = $serviceManager->get('timer');
$duration = $timer->stop('mvc-execution');
// and finally print the duration
error_log("MVC Duration:".$duration." seconds");
}
to this (added two lines at the end of the method):
public function getMvcDuration(MvcEvent $event)
{
// Here we get the service manager
$serviceManager = $event->getApplication()->getServiceManager();
// Get the already created instance of our timer service
$timer = $serviceManager->get('timer');
$duration = $timer->stop('mvc-execution');
// and finally print the duration
error_log("MVC Duration:".$duration." seconds");
$viewModel = $event->getViewModel();
$viewModel->setVariable('mvcDuration', $duration);
}
However, this kind of change does not work and the value of $duration is not passed to the layout. The question is WHY? How can I pass $duration to $this->mvcDuration of the layout?
p.s. The code downloaded from official github repo (https://github.com/slaff/learnzf2) is acting quite strange... Changing project files (e.g.: /module/Debug/view/debug/layout/sidebar.phtml) does not change the output. If You have the same situation while trying to help me with this case then I would suggest you to modify files in /vendor/learnzf2 directory instead of files in /module directory. I know that modifying code in vendor directory is not good thing to do, but let this post (my question) be about the one problem only.
Good book. Your basic problem is that you are Trying to update a variable into the view in a method that is triggered after the view has already been sent. You probably can't do this, unless you redefine which event triggers it, but that would defeat the intended purpose of timing the whole mvc duration.
All that said, you shouldn't be injecting variables into the view model from module.php. It's very hard to test that. This is what view helpers are good for.
I'm trying to use DbTableGateway to store my session information in a MySQL database--but my "sessions" table is remaining empty. It never contains any rows. Here's my code (more or less copy/pasted from here):
$dbAdapter = new Zend\Db\Adapter\Adapter(array(
'driver' => 'pdo_mysql',
'database' => 'db-name',
'username' => 'username',
'password' => 'password!'
));
$tableGateway = new \Zend\Db\TableGateway\TableGateway('session', $dbAdapter);
$saveHandler = new \Zend\Session\SaveHandler\DbTableGateway($tableGateway, new \Zend\Session\SaveHandler\DbTableGatewayOptions());
$manager = new \Zend\Session\SessionManager();
$manager->setSaveHandler($saveHandler);
$someContainer = new Container('SomeSessionNamespace');
$someContainer->aBitOfData = 'tasty morsel of data';
And here's a video demonstration of me using this code:
http://screencast.com/t/UDDUs6OZOib
As you can see in the video, session information is preserved between requests, but it's not being stored in the database.
I added breakpoints to every function in Zend\Session\SaveHandler\DbTableGateway, and the only one that's getting hit is in __constructor. So the constructor is getting called, but apparently it never gets used for anything else.
What am I missing?
I'm using Zend Framework 2.2.2 on PHP 5.3.
-Josh
I found some modules to do that if you need to implement this quickly
https://github.com/Nitecon/DBSessionStorage
https://github.com/gabriel403/G403SessionDb
To use your current code, please check:
options of ** DbTableGatewayOptions** (id, data, lifetime, etc..)
$options = new \Zend\Session\SaveHandler\DbTableGatewayOptions();
$options->setDataColumn('data');
$options->setIdColumn('id');
$options->setLifetimeColumn('lifetime');
$options->setNameColumn('name');
$options->setModifiedColumn('modified');
the start of you SessionManager $manager->start();
Check in application.config.php and make sure the Application module is at the top level
Also make sure that in
'vendor/composer/autoload_namespaces.php' and
'vendor/composer/autoload_static.php'
zend and zendxml library path added or not
eg : 'Zend' => array(vendorDir . '/ZF2/library'),
'ZendXml' => array(vendorDir . '/ZF2/library')
My Problem is the following i wanted to test some functionality that depended on a certain setting in the sfConfig.
Proposed the setting is app_foo and its default is false.
The "standard" way to test is like:
$browser = new sfTestFunctional(new sfBrowser());
$browser->
get('/path_to/index')->
...
end();
BUT it does not work to change the setting like
sfConfig::set('app_foo', true);
$browser = new sfTestFunctional(new sfBrowser());
The sfConfig cannot be overwritten in the test because the sfConfig is reset on the next request.
BUT a field named 'rawConfiguration' in the browser instance is added to the sfConfig for the request. So the solution is to set this array:
$browserEngine = new sfBrowser();
$browser = new sfTestFunctional($browserEngine);
// overwrite an sfConfig parameter in the browser context
$browserEngine->rawConfiguration = array_merge($browserEngine->rawConfiguration, array('app_foo' => true));
Then the action knows the sfConfig::get('app_foo') with the value true.
The samura answer is nice, you also have to know that config files are environement aware so you can do that in your app.yml:
all:
my_setting: "super"
test:
my_setting: "awesome"
This is also working on the database.yml file, allowing you to run functionnal tests in another database