How to get a single attribute from $_POST['Tblmodel'] - yii

Normally,
$model->attributes=$_POST['Tblmodel'];
assigns all the attributes value from $_POST['Tblmodel'] to $model.
I want only to get one attributes value from $_POST['Tblmodel'].
For example:
I only want the value of 'id'. I was trying like this $_POST['Tblmodel']-> id and this doesn't work.
How can i get it?

Can you try this,
$_POST['Tblmodel']['id'];
instead of
$_POST['Tblmodel']-> id

use
$model->attributes=$_POST['Tblmodel'];
$model->id;
Or use
$_POST['Tblmodel']['id'];

Related

Axiomatics - condition editor

I have a subject like "accessTo" = ["123", "123-edit"]
and a resource like "interestedId" = "123"
Now I'm trying to write a condition - where it checks "interestedId" concatenated with "-edit" equals "123-edit" in "AccessTo".
Im trying to write rule like this
anyOfAny_xacml1(function[stringEqual], "accessTo", "interestedId"+"-edit")
It is not allowing to do this.
Any help is appreciated.
In addition to the answer from Keerthi S ...
If you know there should only be one value of interestedId then you can do this to prevent the indeterminate from happening:
stringBagSize(interestedId) == 1 && anyOfAny(function[stringEqual], accessTo, stringOneAndOnly(interestedId) + "-edit")
If more than value is present then evaluation stops prior to reaching the function that expects only one value. This condition would return false if more than one value is present.
On the other hand if interestedId can have multiple values then this would work:
anyOfAny(function[stringEqual], accessTo, map(function[stringConcatenate],interestedId, "-edit"))
The map function will apply the stringConcatenate function to all values in the bag.
Since Axiomatics products are compliant with XACML specification, all attributes by default are assumed to contain multiple values(called as 'bags').
So if you would like to append a string to an attribute use stringOneAndOnly XACML function for the attribute to indicate that the attribute can have only one value.
So assuming you mean accessTo has attribute ID as Attributes.access_subject.subject_id, interestedId has the attribute ID as Attributes.resource.resource_id and anyOfAny_xacml1 is equivalent to anyOfAny XACML function, the resulting condition would look like,
anyOfAny(function[stringEqual], Attributes.access_subject.subject_id, stringOneAndOnly(Attributes.resource.resource_id) + "-edit")

solrj getCountDistinct() return null?

I am trying to get unique value of a field with the code:
query.set("q","*:*" );
query.setGetFieldStatistics(true);
query.setGetFieldStatistics("popu_s");
QueryResponse rsp = solr.query(query);
FieldStatsInfo stats = rsp.getFieldStatsInfo().get("popu_s");
System.out.println(stats.getCount());
System.out.println(stats.getCountDistinct());
stats.getCount() gives the correct count. However, stats.getCountDistinct() always returns null.
Any idea?
getCountDistinct() in FieldStatsInfo is null because it was not provided when creating the FieldStatsInfo object (what was returned from solr.query(query)).
There is no guarantee that any of the fields in this pojo are populated.
As an alternative try using stats.getCardinality() although again there is no guarantee this is poulated.
Found the solution!
To make getCountDistinct() return a value, one needs to add this
query.addStatsFieldCalcDistinct("popu_s", true);

Doctrine 2 with ZF2 how to update row

I am trying to update a row in an entity using:
$linker = $this->getObjectManager()->getRepository('\Schema\Entity\Link')->find('link_id', 7853);
$linker->setSampleTitle($mytitle);
$linker->setSampleDesc($mydesc);
$this->getObjectManager()->merge($linker);
$this->getObjectManager()->flush();
But i get: An open transaction is required for this operation.
Try this:
$this->getObjectManager()->persist($linker);
$this->getObjectManager()->flush();
Also you might want to use findOneBy instead of find.
I just realized that inside the find() method i should not put 'link_id' but the class \Schema\Entity\Link. So getRepository() is not needed here...
Correct is: $linker= $this->getObjectManager()->find('\Schema\Entity\Link', 7853);
$Link = $this->getObjectManager->getRepository('Schema\Entity\Link')->find( 7853 );
and define link_id as id in Entity by #id or use findBy keyword

Rails3 Find Distinct gives result not object

I'm trying to select the User Id as a variable in the console however I keep ending up with:
[#<User id: 4>]
The find statement I have tried is:
userid = User.select('id').where('username = ?', 'uwZgf')
I've also tried with find_by_sql with same result.
What do I need to get the value out instead of the hash?
What you've got there is an array of one User object.
User.select(...).where(...).first.id
Would do the trick (you'd probably want to check the value returned by first before trying to call id on it.
You might find
User.find_by_username('foo').try(:id)
more readable.

Yii framework - picking up field value from other model

I have been struggling with this, i have two models and showing data in Cgridview with one model, this model contains some id's whose values are in different table
So, i have added
'value'=> 'TblAreaoflaw::model()->FindByPk($data->typeoflaw)->areaoflaw'
which is giving this error
"Trying to get property of non-object"
Might be due to this reason that the some records doesn't exist in the TblAreaoflaw. Can't we check in this line through isset?
When i put static value, it work well, like
'value'=> 'TblAreaoflaw::model()->FindByPk(5)->areaoflaw',
Could anyone please help
thanks a lot
The error you get is because this expression TblAreaoflaw::model()->FindByPk($data->typeoflaw) is returning null. This means that you are effectively trying to get null->areaoflaw which won't work (this is what the error message "Trying to get property of non-object" clarifies).
My best guess is that $data->typeoflaw returns a non-existing primary key for the TblAreaoflaw model.
Make sure :
TblAreaoflaw is actually a model, I doubt its Areaoflaw
You have database specified primary key which is the id (5) you are passing
Try:
'value'=> '(TblAreaoflaw::model()->FindByPk($data->typeoflaw)->areaoflaw) ?
: "default or null value"'
Obviously substitute the null string to whatever you want. You may need to adjust the condition to use !empty() or similar, but see how it goes. (And if you do that or aren't using PHP 5.3, use the full ternary expression.)