I want the code to be executed only if i>10. Can you please say what the error is?
<?php $data = wp_excel_cms_get("top100"); ?>
<?php foreach($data as $entry):
{
foreach($entry as $entry[i>10]):
<?php echo $entry[0]." ";?><?php echo $entry[1];?><br />
}
?>
<hr />
<?php endforeach; ?>
Related
I am using cakephp 3. I have to create a view for a Group in which in every Subject, there will be Lessons but in my case:
Group hasMany subjects
Subject hasMany lessons
Here is my code in the GroupsController:
public function mygroup()
{
$this->loadModel('Lessons');
$group = $this->Groups->get($this->Auth->user('group_id'), [
'contain' => ['Subjects', 'Users']
]);
$lesson = $this->Lessons->find('all');
$this->set('lesson', $lesson);
$this->set('_serialize', ['lesson']);
$this->set('group', $group);
$this->set('_serialize', ['group']);
}
I have to load lessons model because it is not associated with group, in mygroup.ctp view:
<?php if (!empty($group->subjects)): ?>
<?php foreach ($group->subjects as $subjects): ?>
<?= h($subjects->subject) ?>
<?= h($subjects->id) ?>
<?= h($subjects->created) ?>
<?php foreach ($lesson as $lesson): ?>
<?php if ($subjects->id == $lesson->subject_id): ?>
<?= h($lesson->lesson) ?>
<?= h($lesson->subject_id) ?>
<?= h($lesson->created) ?></div>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endif; ?>
I want to view lesson just below of its subject where it belongs. I don't know but the for each loop for the subject is working but the for each loop of lessons it only work for the first subject it displays:
Something like this:
Subject1
Lesson1 for sub1
Lesson2 for sub1
Lesson3 for sub1
Subject2
Subject3
Subject4
Subject5
The lessons are not showing in the subject 2 to 5 yet there should be.
Can u help me with this? Or is there any other way to do it? If there someone. Very much appreciate it. Thank you
I have the following code output every iteration of the object. How do I make the output start from the second iteration?
<?php foreach ($data['restos'] as $lid => $resto):?>
<?php
$time_arr = sic_get_start_expire_date_for_user_resto($this->current_user->ID, $lid);
$is_expired_class = '';
if (isset($time_arr['expire_time']) && time()>strtotime( $time_arr['expire_time'] ) ){
$is_expired_class = 'sic-expired-resto';
}
?>
<?php if (!empty($data['restos_metas']['sic_restos_on']) && !empty($level['resto_image_url'])):?>
<div class="resto-outer-wrapper <?php echo $is_expired_class;?>"><img src="<?php echo $resto['resto_image_url'];?>" class="resto" title="<?php echo $resto['label'];?>" /></div>
<?php elseif (!empty($resto['label'])):?>
<div class="sic-above <?php echo $is_expired_class;?>"><?php echo $resto['label'];?></div>
<?php endif;?>
<?php endforeach;?>
The easiest way would be to enclose the output in
if ($uniqueVar) {
// OUTPUT
} else {
$uniquVar = true;
}
Which for your code would look like:
<?php foreach ($data['restos'] as $lid => $resto):?>
<?php
$time_arr = sic_get_start_expire_date_for_user_resto($this->current_user->ID, $lid);
$is_expired_class = '';
if (isset($time_arr['expire_time']) && time()>strtotime( $time_arr['expire_time'] ) ){
$is_expired_class = 'sic-expired-resto';
}
?>
//----------------------------------
<?php if ($notFirstIteration):?>
//----------------------------------
<?php if (!empty($data['restos_metas']['sic_restos_on']) && !empty($level['resto_image_url'])):?>
<div class="resto-outer-wrapper <?php echo $is_expired_class;?>">
<img src="<?php echo $resto['resto_image_url'];?>" class="resto" title="<?php echo $resto['label'];?>" />
</div>
<?php elseif (!empty($resto['label'])):?>
<div class="sic-above <?php echo $is_expired_class;?>"><?php echo $resto['label'];?>
</div>
<?php endif;?>
//--------------------------------
<?php else:?>
<?php $notFirstIteration = true;?>
<?php endif;?>
//--------------------------------
<?php endforeach;?>
This will be true for the second iteration and onward.
using this code
$sisters = array_slice($sisters, 0, 5);
in catalog/controller/module/category.php
I'm displaying only 5 sister categories. I'm having a trouble adding a link stating View More which should link their parent category underneath all sister categories having more than 5 entries.
Any suggestion to solve this?
<?php if ($child['children1']) { $j=0; ?>
<?php foreach ($child['children1'] as $child1) { $j++; ?>
<?php if($j>2) { ?><li class="level-2-cat-list-sub-cat">More...</li><?php break; } else { ?>
<li class="level-2-cat-list-sub-cat" id="<?php echo $i; ?>">
<?php echo strtolower(ucwords($child1['name1'])); ?>
</li>
<?php } ?>
<?php } ?>
<?php } ?>
Make the not on above .tpl file there $j was declared and if it was greater than 2 More... was printed with and anchor tag and ended with "break;" statement
I want to group the form fields like field set or simply enclosed by div. My form needs to be look like below
<form>
<div class="step-1">
Field 1
Field 2
</div>
<div class="step-2">
Field 3
Field 4
</div>
</form>
Graphical example :
Edit : Form class added for reference!
class ProfileForm extends BaseProfileForm
{
public function configure()
{
..... // other widget configuration
$this->embedForm('media', new MediaForm());
}
}
How can I do this in symfony form?
For example:
In action:
$this->form = new MyCoolForm()
In templates:
<form name="form name" id="MyCoolForm" action="<?php echo url_for('action_url') ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php echo $form['name']->render() ?>
<?php echo $form['name']->renderError(); ?>
<fieldset>
<legend>Ppassword:</legend>
<?php echo $form['password']->render() ?>
<?php echo $form['password']->renderError(); ?>
<?php echo $form['password_again']->render() ?>
<?php echo $form['password_again']->renderError(); ?>
<fieldset>
<?php echo $form->renderHiddenFields(); ?>
</form>
etc...
I have an embeddedForm that I am trying to configure the widgets for.
Currently I am just outputting the form in a _form.php template like:
<?php echo $form ?>
This is great, but I'd like to have my form fields in a particular order, so I thought I'd try:
<?php echo $form['firstname']->renderRow() ?>
<?php echo $form['lastname']->renderRow() ?>
<?php echo $form['email_address']->renderRow() ?>
This gives me an invalid widget error.
Now I have 2 forms, one is a basic form, that simply embeds another form.
<?php
class labSupportForm extends sfGuardUserAdminForm
{
public function configure()
{
$form = new labSupportProfileForm($this->getObject()->getProfile());
$this->embedForm('profile', $form);
unset($this['is_super_admin'], $this['is_admin'], $this['permissions_list'], $this['groups_list']);
$this->widgetSchema['profile'] = $form->getWidgetSchema();
$this->validatorSchema['profile'] = $form->getValidatorSchema();
}
public function save($con = null)
{
$user = parent::save($con);
if (!$user->hasGroup('Lab Support'))
{
$user->addGroupByName('Lab Support');
$user->save();
}
return $user;
}
}
and:
<?php
class labSupportProfileForm extends sfGuardUserProfileForm
{
public function configure()
{
unset($this['email_new'],
$this['validate_at'],
$this['validate'],
$this['address_1'],
$this['address_2'],
$this['city'],
$this['country'],
$this['postcode'],
$this['created_at'],
$this['updated_at'],
$this['user_id'],
$this['is_super_admin'],
$this['is_admin'],
$this['permissions_list'],
$this['groups_list']);
}
}
But If I add the widget/validator to the labSupportForm and save, the firstname value doesn't save.
Am I doing something wrong here, as I would have thought this value would save.
Thanks
When you render a form by fields, you have to explicitly call $form->renderHiddenFields(). For example:
<?php echo form_tag_for($form, '#url') ?>
<table>
<tfoot>
<tr>
<td colspan="2">
<input type="submit" value="Save" />
<?php echo $form->renderHiddenFields() ?>
</td>
</tr>
</tfoot>
<tbody>
<?php echo $form['username']->renderRow() ?>
<?php echo $form['profile_form']->renderRow() ?>
</tbody>
</table>
</form>
Also, beware calling embedded form name the same as relation name (e.g. 'profile') or you will have troubles when saving it. Just add '_form' suffix and you will be safe:
$this->embedForm('profile_form', $form);
If you want to keep a linear display structure of your form fields, you should render them explicitly according to your widget schema:
<?php echo $form['username']->renderRow() ?>
<?php echo $form['profile_form']['first_name']->renderRow() ?>
<?php echo $form['profile_form']['last_name']->renderRow() ?>
Or you can do it automatically for all fields of an embedded form:
<?php foreach ($form['profile_form'] as $field): ?>
<?php if (!$field->isHidden()): ?>
<?php echo $field->renderRow() ?>
<?php endif; ?>
<?php endforeach; ?>
Call $this->saveEmbeddedForms() in the labSupportForm save method