I have two tables:supa and acts. Supa table has ID as primary key and and Acts table has supa_ID as a foreign key that is connecting this tables.
Now in table Supa I has field that is called "oznaka".
I suppose to create text field where I will put "oznaka", but in background it is suppose to take ID of Supa table, connect with table Acts, find supa_ID and put him there.
I have troubles with controller function - I suppose I use view - controller only. This doesn't suppose to be hard but I have really trouble :(
<?php echo $form->dropDownList($model,'item_type_id', CHtml::listData(ItemType::model()->findAll(), 'id', 'type'), array('empty'=>'select Type')); ?>
This is basic usage in Yii to create dropdown list, populated from database.
If You want text box, You can make ajax call after some input is received to check whether in database is something that corresponds to this input. If there is, add new value to some hidden input field and get that data when form is sumbitted, in controller.
Related
I am still getting my hands dirty with Symfony, so I am a bit ignorant on how to do something that should be pretty simple.
I have a form that I am creating in the controller and passing to the view:
$form = $this->createForm(new PurchaseOrderType($account), $purchaseOrder);
The form displays exactly how I need it to, no problems at all! I am trying to now make the form more dynamic so that it can auto select a drop down list based upon an "id" variable that I am passing into the form. The id equals 23 by the way.
So, I have a drop down of suppliers and one of the options value is 23. How do I automatically select this option? Sorry for my ignorance :)
Thanks!
Without the code of your form type, I can make only suggestion.
If I get it correctly, inside the purchase order entity, there is an other entity mapped, and that one is represented with an id.
The object, $purchaseOrder has to have the other entity, then in the form type, when you set up the drop down field, you have to specify - with the correct name it shouldn't be a problem - the foreign id.
But you need of course data for the drop down field what can be the result of a SELECT * query.
I have a table which is populated by values obtained from mysql database. I want to use an ajax call function so that when I click a cell - based on the cell value the textboxes get filled. Now the data in the textboxes will be from another table in the mysql database.
So an example of how it would work is:
I have one table for credentials, which shows user name and their user id.
On the website this is shown as a table. Now when i click the a cell which has a user name. The textbox would be populated by the users say total exams taken which is obtained from exams table in the mysql.
I am totally stumped on how to go about doing this. Please can someone help!
You can do this by using ajax .
use this
$("#cell").click(function(){
$.get("file.php?id="+$(this).val(),function(data){
$("#textboxid").val(data);
})
})
the file.php is the file which will perform the back-hand calling to database and make a output.
I want to edit/update, multiple rows together in Yii CGridView.
Say, each row has a checkbox and a single edit/update button, I select multiple rows and by clicking on edit/update button all selected rows are opened for editing and update.
Is this possible with Yii CGridView..??
Use the selectableRows property of the CGridView.
According to Yii Documentation for CGridView
public integer $selectableRows;
the number of table body rows that can be selected. If 0, it means rows cannot be selected. If 1, only one row can be selected. If 2 or any other number, it means multiple rows can be selected. A selected row will have a CSS class named 'selected'.
You can use the the $.fn.yiiGridView.getSelection(containerID) to retrieve the key values of the selected rows.
Add some more buttons either at the top or bottom of the gridview with actions for edit, delete or whatever action you need to take and pass the key values retrieved above.
If you want to edit rows in-line you can use extension phaActiveColumn which I messed up to support multiple rows (the whole table if desired).
EDIT: well, the extension basically creates an input field replacing the grid cell when user clicks on the cell. The field will have the cell's value for starters and it then sends an ajax call to controller, as soon as the user presses enter, asking to save the value of the field, which will be the user's input.
My addition was to create one such field for every cell in the row and store user input in javascript objects which then get send all at once with one ajax call to the controller. Multiple row updates are supported (creating adequate number of javascript objetcs).
If anyone has any interest in this there it is.
phaEditColumn2
phaAbsActiveColumn2
I need MySQL Schema for form generation system, I have created form designer but i need to store it in MySQL.
This system can do following
Create your own form
Add or remove as much fields as you want
Form will connect to a MySQL Table which is going to store form submission data
How it can be done, plz help me
Try using the Entity-attribute-value model (EAV).
Example table for form data:
ID
Name
Value
So for a form with 5 fields, each form would have 5 rows. Name would be the fieldname, value the filled in value.
I have a simple database with multiple tables. I can't figure out how to make cakePHP display the values associated with a foreign key in an index view. Or create a view where the fields of my choice (the ones that make sense to users like location name - not location_id can be updated or viewed on a single page).
I have created an example at http://lovecats.cakeapp.com that illustrate the question. If you look at the page and click the "list cats", you will notice that it shows the location_id field from the locations table. You will also notice that when you click "add cats", you must choose a location_id from the locations table. This is the automagic way that cakePHP builds the app. I want this to be the field location_name.
The database is setup so that the table cats has a foreign key called location_id that has a relationship to a table called locations.
This is my problem: I want these pages to display the location_name instead of the location_id. If you want to login to the application, you can go to http://cakeapp.com/sqldesigners/sql/lovecats and the password 'password' to look at the db relationships, etc.
How do I have a page that shows the fields that I want? And is it possible to create a page that updates fields from all of the tables at once?
This is the slice of cake that I have been trying to figure out and this would REALLY get me over a hump. You can download the app and sql from the above url.
Hah, you figured it out correctly! Cake uses the $displayField variable do decide what to..well, display.
If I remember correctly, by default, cake looks for 'title' and 'name' fields, and if those two are not available, it will simply show your primary key field. Luckily, you can override it the way you figured out yourself ;)
I guess you need to echo $cat['Location']['location_name'] in your view.