How to set multidimentional session array in Yii - arrays

I am trying to set a multidimensional session array using Yii but I keep getting the following error:
Indirect modification of overloaded element of CHttpSession has no effect
Can someone point me in the right direction, below is the code:
/ $params = Util::Get_POST_Params();
$session = Yii::app()->session;
$session['Cart']['OfferName'] = $params['offer_name'];
$session['Cart']['OfferFee'] = $params['offer_fee'];
Thank you.

After a little reading adding creating a temp array and using the Yii method "add" to add in the session, it did the trick form. below is the working code.
$session = Yii::app()->session;
$cartArray = array('OfferName'=>$params['offer_name'],'OfferFee'=>$params['offer_fee']);
$session->add('cart',$cartArray);

Related

How to create a file screen exception in powershell (FSRM Api)

I need to create file screen exception in powershell using the FSRM Api, I am using this script to create the cuota but I am having trouble to commit the object.
Because I haven't achieved to meet the requirement to modify AllowedFileGroups property :(
$FSRMObject = New-Object -Com Fsrm.FsrmFilescreenManager
$createFileScreenException = $FSRMObject.CreateFileScreenException("c:\")
$createFileScreenException.AllowedFileGroups("Text Files")
$createFileScreenException.Commit()
This is what I get Listing the Properties and Methods of the Object, in the property definition of AllowedFileGroups I can see that I need to create IFsrmMutableCollection.
Does anyone have an idea of how to create the file screen exception?
AllowedFileGroups is a property, not a method, so I'd expect something like this to work:
$createFileScreenException = $FSRMObject.CreateFileScreenException('c:\')
$createFileScreenException.AllowedFileGroups = 'Text Files'
$createFileScreenException.Commit()
Can't test it, though.
This is how you can create the simplest quota using the FSRM api in powershell, to view more modificable options get the members of the object $quota.
$fsrmQuotaObject = New-Object -Com FSrm.FsrmQuotaManager
$quota = $fsrmQuotaObject.CreateQuota("c:\path")
$quota.ApplyTemplate("Select template")
$quota.Commit()

can't manipulate JSON obtained through multiple $http.get and $q

I am trying to merge two jsons into one but can't make it work. I manage to retrieve the data I need from both get, but I have troubles manipulating the jsons.
I planned on using two for loops but it doesn't work :
$scope.coursesJson = $http.get('https://api.myjson.com/bins/18zi3');
$scope.reviewsJson = $http.get('https://api.myjson.com/bins/52toz');
$q.all([$scope.coursesJson, $scope.reviewsJson]).then(function (values){
$scope.coursesJson = values[0];
$scope.reviewsJson = values[1];
for(i = 0;i<$scope.coursesJson.length;i++){
for(j = 0;j<$scope.reviewsJson.length;j++){
if($scope.coursesJson[i].name = $scope.reviewsJson[j].name){
$scope.coursesJson[i].reviews.push($scope.reviewsJson[j]);
}
}
}
console.log($scope.coursesJson);
});
Using the console, I can visualise the data but $scope.coursesJson.length is undefined and I don't understand why.
Maybe I don't understand $q well ?
EDIT :
Here is an example of the elements you could find in the coursesJson file I get() :
[{"code":"123 ","name":"Acteurs","courseContentGrade":null,"courseTeachingGrade":null,"courseAverage":null,"reviews":null},
{"code":"1234","name":"Advanced Excel","courseContentGrade":null,"courseTeachingGrade":null,"courseAverage":null,"reviews":null}]
And an example of the elements you could find in the reviewsJson file I get() :
[{"code":"123 ","name":"Acteurs","professor":"Lalala","contentReview":"C'est très réussi.","teachingReview":"charismatique","contentGrade":8,"teachingGrade":8,"average":8,"trimester":"T2","day":"Jeudi / Thursday","time":"9h-12h","round":"1er tour","bet":21,"year":"2014/2015","upvotes":"0","author":"Piranha","passed":null},
{"code":"123 ","name":"Acteurs","professor":"LAlalalala","contentReview":"Très intéressant !","teachingReview":"Disponible, claire.","contentGrade":8,"teachingGrade":8,"average":8,"trimester":"T2","day":"Jeudi / Thursday","time":"9h-12h","round":"1er tour","bet":25,"year":"2014/2015","upvotes":"0","author":"Piranha","passed":null}]
I would like to add the elements found in the reviewsJson to the reviews field of the elements of coursesJson. Could that be the problem ? I thought that using the push() method would create the array, but maybe I need to change all "reviews":null to "reviews":[] in coursesJson ?
I went to the url https://api.myjson.com/bins/ID1 and it's not an array, but an object. Instead of $scope.coursesJson.length I think you shouldbe doing $scope.coursesJson.tracks.length
I solved my issue really easyly and my question was actually pretty stupid.
What I tried to achieve didn't have its place on the front but on the backend.

Symfony session get array value

I'm using Symfony2, and are having trouble getting array values stored in a session, without putting them in a variable or object.
Possible something like:
echo $app['session']->get('shop')->get('name');
Currently I'm achieving it by doing this, but I would like to avoid it for the cause of simplicity:
$temp = $app['session']->get('shop');
echo $temp['name'];
Is it possible?
Thanks in advance
The session object is just a "parameter bag", an object that holds keys & values.
If you want to create another level of that mechanism you would have to instantiate your own bag.
$shop = new \Symfony\Component\HttpFoundation\ParameterBag;
$shop->set('name', 'Fantastic Warehouse');
$app['session']->set('shop', $shop);
// next request
echo $app['session']->get('shop')->get('name');

In Magento how do you get the database name?

How do you get the database name from Magento?
I have seen functions like the one below that can get the table name.
$orderItemTable = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
I was hoping that there was some sort of function like this:
Mage::getSingleton('core/resource')->getDatabaseName();
Thanks in advance for any ideas.
Each module can specify it's own connection so you are right to go via a model.
$config = Mage::getResourceModel('sales/order')->getConnection()->getConfig();
// $config is an array
$dbname = $config['dbname'];
If you're only interested in the default a slightly more efficient way might be:
$dbname = (string)Mage::getConfig()->getNode('global/resources/default_setup/connection/dbname');
To get the db name try
Mage::getConfig()->getResourceConnectionConfig('default_setup')->dbname;
See How to get magento database details
It is always possible to get the current connection from Mage::getSingleton('core/resource')->getConnection('core_write'), quite specially if you use only one database.
$configArray = Mage::getSingleton('core/resource')->getConnection('core_write')->getConfig();
$db = $configArray['name'];
But it's comming with a zend adapter Zend_Config
// Create the object-oriented wrapper upon the configuration data
$config = new Zend_Config($configArray);
$db = $config->get('dbname');

Is it possible to 'prepare' a Propel 1.4 Criteria so it can be used efficiently inside a loop?

I'm using symfony 1.3 with Propel 1.4. I need to use a prepared query that will be used inside a loop changing the values of bound parameters.
Is it possible to do this with Propel 1.4? I want to retrieve results as objects so don't want to use raw SQL if I can help it.
Propel does not seem to support this out of the box. Take one of the examples, the Book class. BookPeer::doSelect() calls BookPeer::doSelectStmt() and passes the result to BookPeer::populateObjects(). BookPeer::doSelectStmt() calls BasePeer::doSelect(), which always calls BasePeer::createSelectSql() to create the SQL statement, prepares it, and passes it to BasePeer::populateStmtValues() to actually bind the values.
You can take code from these methods to get something like this (without exception or transaction handling):
$criteria = new Criteria();
$criteria->addThis();
$criteria->addThat();
$con = Propel::getConnection($criteria->getDbName(), Propel::CONNECTION_READ);
$params = array();
$sql = BasePeer::createSelectSql($criteria, $params);
$stmt = $con->prepare($sql);
// $stmt is a prepared PDOStatement
// $params is an array of the form: [{'table': 'tableName', 'column': 'columnName', 'value': 'paramValue'}, ...]
// You can keep this format and use BasePeer::populateStmtValues(), or you can call $stmt->bindParam() yourself
// Now in the loop, we set the params ourself
foreach ($loop as $loopData) {
// Bind the params, using your preferred method
// ...
// Pass the prepared and bound statement to populateObjects()
$books = BookPeer::populateObjects($stmt);
// Do something with the found objects
// ...
}

Resources