How to set checkbox label position without using formMultiCheckbox(...) in ZF2? - checkbox

I want to be able to set the label position:
for the entire element and
(in case of checkboxes / radio buttons) additionally for every single checkbox / radio button.
I have a form, that is build like this:
<?php
$form = $this->form;
$form->setAttribute('action', $this->url());
$form->prepare();
echo $this->form()->openTag($form);
?>
<?php $fooFieldset = $form->get('foo'); ?>
<div id="fieldset-foo" class="fieldset-container col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $this->translate($fooFieldset->getLabel()); ?></h3>
</div>
<div class="panel-body">
<?php foreach ($fooFieldset as $element) : ?>
<div class="form-group <?php if($this->formElementErrors($element)) echo 'error' ?>">
<?php $element->setOption('label_position', FormRow::LABEL_PREPEND); /* not working! */ ?>
<label><?php echo $this->translate($element->getLabel()); ?></label>
<div>
<?php $element->setAttribute('class', 'form-control'); ?>
<?php echo $this->formElement($element); ?>
<?php if ($this->formElementErrors($element)) : ?>
<div class="message-error"><?php echo $this->formElementErrors($element) ?></div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<!-- futher fieldsets -->
<!-- fields without fieldsets -->
<?php
echo $this->form()->closeTag($form);
?>
That means, I'm not calling the formRow(...) or formMultiCheckbox(...) and cannot configure the label_position on this way. The setting an option directly on the element ($element->setOption('label_position', FormRow::LABEL_PREPEND)) does not work at all -- neither for the entire element nor for checkboxes / radio buttons.
How to get it working and set the label position (1. for the entire element; 2. for the checkboxes / radio buttons) here?

Related

View inside a view using CakePHP 3

Is it possible to display a view inside another view?
I have the following code:
<?php if ($result->type === 'brochure') : ?>
<div>
// massive template block
</div>
<?php elseif ($result->type === 'library') : ?>
<div>
// massive template block different from above
</div>
<?php else : ?>
<div>
// massive template block different from both above
</div>
<?php endif; ?>
I want to replace those with a content block so to speak. I had a look at view blocks but I'm either using it wrong or it doesn't do what I want it to do.
Is this possible in CakePHP 3?
you can use elements for that.
first you should create elements in src/Template/Element directory with .ctp format like this
// in brochure.ctp file in src/Template/Element
<div>
// your massive template block
</div>
then you can call elements like this :
<?php if ($result->type === 'brochure') : ?>
<?= $this->element("brochure") ?>
<?php elseif ($result->type === 'library') : ?>
<?= $this->element("library") ?>
<?php else : ?>
<?= $this->element("default") ?>
<?php endif; ?>

codeigniter model does not return results as defined on limt

this is my model
function get_one_news($limit = 2, $offset = null) {
if ($limit) {
$this->db->limit($limit, $offset);
}
$this->db->order_by('news.added_on', 'desc');
return $this->db->get('news');
}
and in my controller i had assign it like
$data['news'] = $this->news_model->get_one_news();
in my view i had implement it like
<div class="col-md-8 col-lg-8">
<!-- artigo em destaque -->
<?php if ($news->num_rows()):?>
<?php foreach ($news->result() as $n):?>
<?php if ($n->cat_id == 17):?>
<div class="featured-article">
<a href="#">
<?php if ($n->image != ''): ?>
<img src="<?php echo base_url('uploads/'.$n->image);?>" alt="" class="thumb">
<?php endif;?>
</a>
<div class="block-title">
<h4><?php echo $n->title = word_limiter($n->title, 7);?></h4>
</div>
</div>
<!-- /.featured-article -->
<?php endif;?>
<?php endforeach;?>
<?php endif;?>
</div>
this query
gives me result but if i put limit 3 it gives 2 if i put 2 it gives 1 and if i put 1 it wont give any result why ?
What happens if you echo $news->num_rows()? I suspect it might have something to do with:
<?php if ($n->cat_id == 17):?>
Are you getting the same number of rows as your limit but it is filtering out the most recent one because it isn't cat_id == 17?

Drupal 7 displaying content issue

How to hide a specific field of basic page content type? Not from admin pannel Structure>content type>basic page> manage display.. I want to hide it in my page template then showing separatly so that i can customize it?
In your template, you can use the hide function to prevent fields from being rendered.
Here's an exampled from the Garland theme's node template:
<div class="content clearfix"<?php print $content_attributes; ?>>
<?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
print render($content);
?>
</div>
<div class="clearfix">
<?php if (!empty($content['links'])): ?>
<div class="links"><?php print render($content['links']); ?></div>
<?php endif; ?>
<?php print render($content['comments']); ?>
</div>

How to get controller view inside an element?

I have created an element having a text field(Status Bar same as Facebook) which i extended in home/display view.
Code for element:
<?php
echo $this->Html->css('notes');
echo $this->Html->script(array('jquery','jquery.elastic','notes'));
?>
<div class="notescontainer">
<div class="share">Share:</div>
<div class="notes">Notes</div>
<div class="loading"></div>
<div class="img_top"></div>
<div class="text_status">
<?php
echo $this->form->create('Note', array('action' => 'notes'));
echo $this->form->input('notes',array('class' => 'notesbar', 'label'=>'', 'placeholder' => 'Write down you notes ...'));
?>
</div>
<div class="button_outside_border" id="share">
<div class="button_inside_border">
<?php
echo $this->form->submit('Share',array('alt' => 'Add', 'class' => 'sharebutton'));
echo $this->form->end();
?>
</div>
</div>
<div class="clear"></div>
<div class="load_status_out"></div>
</div>
I want that when user shares the status it should re-appear on the same page that is display/home and for that i created a controller for retrieving the status entered by the user.
Controller:
<?php public function notes()
{
$this->set('allnotes', $this->Note->find('all'));
}?>
Controller View:
<?php
foreach($allnotes as $viewnotes):
{
echo $viewnotes['Note']['notes'];
echo "<br>";
}
endforeach;
?>
Now i want this controller view to be displayed on home/display view. Is there any way i can extend it in that element? I don`t want to add it directly on my home/display view as it already fully loaded.
You can use requestAction() to accomplish this, but in my experience it is buggy and a sign of design failure if you need it.
Alternatively you can turn all your view into elements, which can be embedded in each other in any arbitrary way. Then you can just call some shared code in the controller to populate all required models.

change position of the flash message

I have something like this:
controller.
public function add() {
$this->layout = 'home';
$this->Session->destroy();
if ($this->request->is('post')) {
$this->Session->setFlash(__('xxx', true));
}
}
view. home.ctp
<div id="container">
<div id="header">
</div>
<div id="content">
<?php echo $this->fetch('content'); ?>
</div>
<div id="footer">
<?php echo $this->Session->flash(); ?>
</div>
</div>
My question is: Why the flash message is not showed in the footer? well, what I want is show the message below the form, but to simplify the problem, with this code the message is also showed in the top. But should be in the footer. Also if i delete
<?php echo $this->Session->flash(); ?>
the message is also showed on the top of the page.
So, how can i change the position of this flash message?
Edit:
<?php var_dump($this->fetch('content')); ?>
output:
string '<div id="flashMessage" class="message"> The user xxxxx</div>
<div class="users form">
<form action="/cake/users/add" id="UserAddForm" method="post" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST"/></div> <fieldset>
<legend>
Add User
</legend>
<div class="input text required error"><label for="UserUsername">Username</label><input name="data[User][username]" maxlength="50" type="text" value="" id="UserUsername" class="form-er'... (length=1187)
You are setting the layout to 'home', is that right? Did you create a home.ctp under views/layouts? I ask you because the view that you show looks like the default layout shipped with Cake (default.ctp).
For me, the code looks fine mate, just be sure you are displaying the right layout.
When I delete my <?php echo $this->Session->flash(); ?> I don't get flash messages. I think you should consider #clapas's answer.

Resources