I have tried to make dropdown list but why its just empety result?
This is the way i made the drop down
$form->field($model, 'ID_DATA_PROPERTIES')->dropDownList($list_properties, ['prompt'=>'-Choose a Course-'])
This app/models/Request :
i have table request
* #property integer $ID_REQUEST
* #property integer $ID_DATA_PROPERTIES //foreignkeys
//request related to data_properties
* #property DataProperties $iDDATAPROPERTIES
/**
* #return \yii\db\ActiveQuery
*/
public function getIDDATAPROPERTIES()
{
return $this->hasOne(DataProperties::className(), ['ID_DATA_PROPERTIES' => 'ID_DATA_PROPERTIES']);
}
The table data_properties : ID_DATA_PROPERTIES, NAMA_DATA_PROPERTIES
The controller :
$model = new Requestdata();
$list_properties = ArrayHelper::map(Requestdata::find()->all(), 'iDDATAPROPERTIES', 'NAMA_DATA_PROPERTIES');
i found the answer, i was put wrong model.
i made dataproperties model by gii. and use it for find data list i need
$list_properties = ArrayHelper::map(DataProperties::find()->all(), 'ID_DATA_PROPERTIES', 'NAMA_DATA_PROPERTIES');
Related
I have related tables (table train_schedule have departute_station_id and arrival_station_id) linked on Station:
enter image description here
I want select records from train_schedule with stations name:
$trainsTchedule = TrainSchedule::find()
->joinWith('getArrivalStation')
->joinWith('getDepartuteStation()')
->all();
In TrainSchedule class:
/**
* #return \yii\db\ActiveQuery
*/
public function getArrivalStation()
{
return $this->hasOne(Station::className(), ['id' => 'arrival_station_id']);
}
And
/**
* #return \yii\db\ActiveQuery
*/
public function getDepartuteStation()
{
return $this->hasOne(Station::className(), ['id' => 'departute_station_id']);
}
Error:
Relation names are case sensitive. app\models\TrainSchedule has a
relation named "arrivalStation" instead of "ArrivalStation".
Howe get data wrom linked tables?
You have defined your relations correctly but, you are calling them incorrectly. Your relation
getArrivalStation should be specified as arrivalStation
getDepartuteStation() should be departuteStation
when specifying in the joinWith, and you need to provide an array if you need to specify multiple relations when calling joinWith as currently your second call ->joinWith('getDepartuteStation()') is overriding the previous one ->joinWith('getArrivalStation').
So the query should look like below
$trainsTchedule = TrainSchedule::find()
->joinWith(['arrivalStation','departuteStation'])
->all();
You should read about Working with Relational Data
I need help on this, I have a model
/**
* This is the model class for table "student_attachment_details".
*
* #property integer $createdBy
* #property string $reg_no
* #property string $county_attached
* #property string $closest_town
* #property string $company_attached
* #property integer $company_phone_number
* #property string $is_assessed
* #property string $location_description
* #property integer $department_id
* #property string $allocated_staff_id
*/
class StudentAttachmentDetails extends \yii\db\ActiveRecord
{
But when i try to query the model like this
$student_details = StudentAttachmentDetails::find()
->where(['allocated_staff_id'=>'no'])
->limit(1);
And then try to get a value with this
$reg_no = $student_details->reg_no;
I get this error
Getting unknown property: yii\db\ActiveQuery::reg_no
What am I doing wrong?
the method ActiveRecord::find() returns an ActiveQuery; to access the actual model (in your case of class StudentAttachmentDetails) you need to call a method to execute the ActiveQuery.
something like
$student_details = StudentAttachmentDetails::find()
->where(['allocated_staff_id'=>'no'])
->limit(1)->one();
will give you the record you are looking for. The docs for ActiveRecord::find() can be found here and ActiveQuery::one() here.
I have a class Person with about 100 fields.
recently i added a new field:
/**
*
* #ORM\Entity
* #Vich\Uploadable
* #ORM\Entity(repositoryClass="My\VenderBundle\Repository\PersonRepository")
* #ORM\Table(name="my_vendor_person")
*/
class Person
{
....
/**
* My new property
*
* #var array $references
*
* #ORM\Column(name="references", type="array", nullable=true)
*/
protected $references;
The form type has been updated accordingly:
class PersonInvitationType extends AbstractType
{
private $context;
/**
* PersonNewType constructor.
* #param AuthorizationChecker $securityContext
*/
public function __construct(AuthorizationChecker $securityContext)
{
$this->context = $securityContext;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('references', CollectionType::class, array(
'entry_type' => Referencese::class,
'label' => 'References',
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'prototype_name' => 'references__name__',
'by_reference' => false,
'required' => false
))
But now I am getting the following error when submitting a form containing almost all fields of class Person:
An exception occurred while executing 'UPDATE my_vendor_person
SET references = ? WHERE id = ?' with params
["a:1:{s:7:\"myProperty0\";a:4:{s:4:\"name\";s:7:\"my name\";s:6:\"location\";
s:9:\"my location\";s:5:\"phone\";s:8:\"90898978978\";s:5:\"email\";
s:17:\"myemail#gmail.com\";}}", 765]:
Below that, the following is stated:
QLSTATE[42000]: Syntax error or access violation: 1118 Row size too large
(> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or
ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored
inline.
The form contains more fields of type array which contain more information then the above example. someone has an idea of what is happening here? Am Running Symfony 3.
UPDATE:
please find a pastbin of the dev.log here: http://pastebin.com/0qLm60x7
SECOND UPDATE:
please find the create table statement here: http://pastebin.com/PFy5jAbx
I'm receiving a list of elements from an API. All the elements are well formatted. When I dump one of them using twig, I get the following :
Leg {#2695 ▼
-id: null
#reservation: null
-airportStart: "AIX LES MILLES"
-airplaneType: "Cessna Citation Mustang"
-airportEnd: "ROBINSON"
-startDate: "2015-09-10 20:00:00"
-startHour: "2015-09-10 20:00:00"
-endHour: "2015-09-10 21:00:21"
-durationLeg: "01:21"
#nbPax: "4"
-price: null
-updatedPrice: null
-discountOnLeg: null
-tva: null
-status: null
}
My user must select one of these elements, So what I'm trying to do is to send the encoded json back to the controller, using
{{ element|json_encode }}
Unfortunately, the json is empty. When I try to dump the encoded json using
{{ dump(element|json_encode) }}
all I get is an empty array {};
Any idea why Is there another way to send the selected element datas to a controller function? (These elements are not persisted, each call on the API returns thousands of results)
I'm little late to the party (2 years of lateness), but for any one like me coming from a google research i say : i had the same problem too, and after googling around, i "solved" my problem with the Serializer Component. How? let me show you!
Installation
php composer.phar require symfony/serializer
Entity
<?php
namespace Your\Namespace\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
/**
* Leg
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Your\Namespace\Entity\LegRepository")
*/
class Leg {
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
...
public function serializer()
{
$encoder = new JsonEncoder();
$normalizer = new ObjectNormalizer();
$normalizer->setIgnoredAttributes(array(
'whatever', 'attributes', 'you', 'want', 'to', 'ignore'
));
// The setCircularReferenceLimit() method of this normalizer sets the number
// of times it will serialize the same object
// before considering it a circular reference. Its default value is 1.
$normalizer->setCircularReferenceHandler(function ($object) {
return $object->getName();
});
$serializer = new Serializer(array($normalizer), array($encoder));
return $serializer->serialize($this, 'json');
}
}
Twig
{{ Leg.serializer|raw }}
N.B : this is tested under symfony 2.6
I have problem with my User Entity. I have code generated by Doctrine it is below:
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="Frontend\UserBundle\Entity\SfGuardPermission", inversedBy="user")
* #ORM\JoinTable(name="sf_guard_user_permission",
* joinColumns={
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="permission_id", referencedColumnName="id")
* }
* )
*/
protected $permission;
Problem is with join because I can't join user and permission. What I must to do? I must join sf_guard_user with sf_guard_user_group with sf_guard_grop with sf_guard_group_permission with sf_guard_permission. Because I need to get User permission. I do not no how to write join like this in code above. Is it possible?
You can not write this join in one annotation. In fact you gone have three entity tables sf_guard_user, sf_guard_group and sf_guard_permission and two cross tables which you can write as you already started, sf_guard_user_group and sf_guard_group_permission.
But since it looks like you try to migrate some symfony 1.x stuff to symfony 2.x:
The sf_guard_user_permisson table in symfony 1.x is a cross table between users and permission, containing extraordinaire permission for a user which are not granted through the groups the user is in, so you are already done.
SBH thx for replay, of course you have right with everything what you have written. But my sf_guard_user_permisson is empty so I can't use it. I can generate this table, this is no problem, but then I will must maintain it. This is next work for me so i wrote code below:
namespace Frontend\UserBundle\Entity;
// ...
/**
* #var \Doctrine\Common\Collections\Collection
*
*/
protected $permissions;
/**
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getPermissions()
{
$groups = $this->getSfGuardGroups();
foreach ($groups as $group)
{
$groupPermisions = $group->getPermission();
foreach ($groupPermisions as $groupPermision)
{
if (!in_array($groupPermision, $this->permissions)) {
$this->permissions[] = $groupPermision;
}
}
}
return $this->permissions;
}
/**
* #param string $permissionName
* #return boolean
*/
public function hasPermission($permissionName)
{
$this->getPermissions();
foreach ($this->permissions as $permission)
{
if($permission->getName() === $permissionName) {
return true;
}
}
return false;
}
// ..
What do you think about it? Your opinion is very important for me.
Edit:
Thx for SBH help, I have got answer for my question. I have hope it will help other people. If you do not understand something please look at SBH answer.