In my cake application, I have a model called faqs, the controller is called faqs_controller and the view is called faqsindex.php.
I am creating a CMS so that users can modify frequently asked questions. The db faqs table has 5 columns id, category, question, answer and number. "Number" is the order in which the FAQ appears.
The cycle that lists all the frequently asked questions looks something like this:
<?php
foreach ($faqs as $faq):
<tr>
<td><?php echo $faq['Faq']['category']; ?></td>
<td><?php echo $faq['Faq']['number']; ?></td>
<td><?php echo $faq['Faq']['question']; ?></td>
<td><?php echo $faq['Faq']['answer']; ?></td>
</tr>
<?php endforeach; ?>
I want to make it possible for the user to change the cell "number" on this screen, instead of going to a separate editing screen for each line and changing the number there.
, Netflix, , , , .
edit faqs_controller.php :
function edit() {
if(!empty($this->data)) {
$this->Faq->saveAll($this->data['Faq']);
}
else {
$this->data['Faq'] = Set::combine($this->Faq->find('all'), '{n}.Faq.id', '{n}.Faq');
}
}
foreach, :
echo $form->create('Faq', array('action'=>'edit'));
foreach($this->viewVars['faqs'] as $key => $value) {
echo 'id:'.$value['Faq']['id'];
echo '<br/>question:'.$value['Faq']['question'];
echo $form->input('Faq.'.$key.'.number');
}
foreach 8 , 8 . , 8 .
-Edit -
echo :
echo $form- > input ('Faq.'. $key. '. question', array ('value' = > $value ['Faq'] ['question']));
. , . , 8 mysql, :
INSERT INTO faqs (question) ( " ?" ), , .