Please i need a big help here. AM developing a yii application where i have to loop through my form and do a batch insert. I found bacth update in yii but ive not been able to see how to do batch insert and validation. Please help.
Here is my View:
<?php for($i=0;$i< $this->getDisplayArchModel();$i++) {?>
<FIELDSET class="radios">
<div class="row">
<?php echo $form->labelEx($model,'competency_type'); ?>
<?php echo $form->textField($model,'competency_type'); ?>
<?php echo $form->error($model,'competency_type'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'definition'); ?>
<?php echo $form->textArea($model,'definition'); ?>
<?php echo $form->error($model,'definition'); ?>
</div>
</fieldset>
<?php } ?>
Controller ::
public function actionDisplayArchModel()
{
$validateCat = $this->getDisplayArchModel();
if($validateCat == NULL)
$this->redirect(array('architecture'));
$model = new CompetencyType;
if(isset($_POST['CompetencyType']))
{
$model->attributes = $_POST['CompetencyType'];
if($model->validate()){
foreach($_POST['CompetencyType'] as $value)
{
echo $value;
}
}
}
$this->render('displayArchModel' ,array('model'=>$model));
}
Sometimes we want to collect user input in a batch mode. That is, the user can enter the information for multiple model instances and submit them all at once. We call this tabular input because the input fields are often presented in an HTML table.
To work with tabular input, we first need to create or populate an array of model instances, depending on whether we are inserting or updating the data. We then retrieve the user input data from the $_POST variable and assign it to each model. A slight difference from single model input is that we retrieve the input data using $_POST['ModelClass'][$i] instead of $_POST['ModelClass'].
more on collecting Tabular Input
Related
<div><Strong>Name: </strong><?= $record['Childvaccination']['name']; ?></div>
When data is not coming then it is showing "Name:" only but I also want to hide name if data is not coming or it is empty.
This is cakephp ctp file.
You want to check if the value is empty or not and output accordingly:-
<?php if (!empty($record['Childvaccination']['name'])): ?>
<div><Strong>Name: </strong><?= $record['Childvaccination']['name']; ?></div>
<?php endif; ?>
I am new to cakephp framework and i am using cakephp3.0 now i used baking concept instead of using scaffolding. After baking it automatically generated all pages based on my tables in database and it generated code in models,controllers and views.Now my question is "if it is possible to change the code in views to change field types (from text box to radio button) according to my requirements."
Please help me.
Thanks in advance
Yes, after you bake your project you can change the fields types. Navigate to the folder where all your views are located, for example: app\View\MyViewName. Baking is a great tool to get something up and running fast. If you have a fairly structured website mostly used for data entry this is a great tool. I used it for simple data entry websites and it has saved me so much typing! Just add some data validation/constraints in the model and you're good to go!
A freshly baked view will look a little something like this:
<div class="MyForm Form">
<?php echo $this->Form->create('MyForm'); ?>
<fieldset>
<legend><?php echo __('Add My Form'); ?></legend>
<?php
echo $this->Form->input('field1');
echo $this->Form->input('field2');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List My Forms'), array('action' => 'index')); ?></li>
</ul>
</div>
Change the input methods to look something like this:
$options = array('Y' => 'Yes', 'N' => 'No');
echo $this->Form->radio('myFields', $options);
I have an IT query system were by users can add their queries, when they add their query the IT department then replies/comments on the query.
How is should work is when the user adds a query it must change the query_type field in the it_queries table to OPEN and when the IT department views the query they reply/comment on it and must change query_type field from OPEN to PENDING then finally when the user has been helped/assisted they should be able to mark the query as closed using a checkbox, that will then change the status from PENDING TO CLOSE.
Not sure if they is a way of setting the constants in the add views and insert in the table.
Obviously i am learning and can someone please guide me on the steps i must take.
Here is my code for the add it_query for the users
<?php echo $this->Form->create('ItQuery'); ?>
<fieldset>
<legend><?php echo __('Add It Query'); ?></legend>
<?php
echo $this->Form->hidden('hr_employee_id',array('value'=>$loggedInId));
echo $this->Form->input('it_query_type_id');
echo $this->Form->input('comment');
echo $this->Form->hidden('status_type', array('value'=>OPEN));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
Here is the code for my comments for IT Department
<?php echo $this->Form->create('ItQueryComment'); ?>
<?php echo __('Add It Query Comment'); ?>
<?php
echo $this->Form->input('it_query_id');
echo $this->Form->input('comment');
echo $this->Form->input('close_query');
?>
<?php echo $this->Form->end(__('Submit')); ?>
Here is the code for my ItQueryComments
public function add() {
if ($this->request->is('post')) {
$this->ItQueryComment->create();
if ($this->ItQueryComment->save($this->request->data)) {
$this->Session->setFlash(__('The it query comment has been saved'));
$this->redirect(array('controller' => 'it_queries','action' => 'view', $this->request->data['ItQueryComment']['it_query_id']));
} else {
$this->Session->setFlash(__('The it query comment could not be saved. Please, try again.'));
}
}
$itQueries = $this->ItQueryComment->ItQuery->find('list');
$hrEmployees = $this->ItQueryComment->HrEmployee->find('list');
$this->set(compact('itQueries', 'hrEmployees'));
}
While saving a comment for a particular Itquery , in your add function of Comments Controller after adding comment to database get its id by using $this->getLastInsertID();
and call function updateAll for Itquery Model and change status of that particular Query to "Pending".
On my Magento product page; when a product has multiple values for one custom attribute; instead of displaying the values it displays the text "array". It works fine with one value.
Thanks,
-Sam
You can do something like:
<?php
foreach($_product->getMetal() as $name => $value): ?>
<?php echo $name;?> = <?php echo $value;?>
<?php
endforeach; ?>
Magento takes advantage of PHP's magic getter/setter functionality (http://www.php.net/manual/en/language.oop5.overloading.php#object.get).
You can do a vardump($_product) to see the available attributes (they are stored in the _data array in the product). Then to retrieve one of them, you just remove the underscores and change the first letter of each word to uppercase.
EDIT:
If the above code doesn't output values, you can do this (which will tell you how to get to the value):
<?php
foreach($_product->getMetal() as $attribute): ?>
<?php var_dump($attribute); ?>
<?php
endforeach; ?>
I found this on Magento forums and it seems to work:
` getData('attribute_name')): ?>
getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product)) ?>
`
I have a model named google_news.php which uses the external data, and another model saved_news.php which uses my saved_news table in database,
In my controller I declared that Im using this two models:
var $uses = array('GoogleNews', 'SavedNews');
and my index function reads data:
$this->set('news',$this->GoogleNews->find('all'));
and my view looks like this:
<?php foreach( $news as $newsItem ) : ?>
<?php echo $html->link($newsItem['GoogleNews']['title'], array('action'=>'add', $newsItem['GoogleNews']['title'])); ?>
<?php echo $newsItem['GoogleNews']['encoded']; ?>
<em>
<hr>
<?php endforeach; ?>
How to write the add function in my controller to save each data to my database?
You should assign what you need to be saved into $this->data['ModelName'] as array of fields. Take a look at saving data in the book. That will explain more about the formatting that needs to be followed.