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.
Related
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?
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>
I need some help to create a simple search form with one input box. It needs to be able to send a value to a controller in the url like so:
http://mysite.co.uk/properties/results?search=northampton
I would like to use the cakePHP form helper, but can you include an input that doesnt relate to a column in the database?
have since found the answer to this:
///in the view:///
<div class="container">
Property Search</div>
<div class="col-md-12 purple search_box">
<?php
echo $this->Form->create('Properties', array('type' => 'get'));
echo $this->Form->input('search', array('between'=>'<label for="search" class="main_search">Search</label><br>','label'=>false));
echo $this->Form->button('Search', array('class'=>'btn btn-success'));
echo $this->Form->end
?>
</div>
</div>
//in the controller//
if(isset($this->params['url']['search'])){
echo 'search text has been found';
}
Fair comment burzum
This is the example in the book, of a simple View Template
// app/View/Common/view.ctp
<h1><?php echo $this->fetch('title'); ?></h1>
<?php echo $this->fetch('content'); ?>
<div class="actions">
<h3>Related actions</h3>
<ul>
<?php echo $this->fetch('sidebar'); ?>
</ul> </div>
And this is how it might be extended
// app/View/Posts/view.ctp
<?php
$this->extend('/Common/view');
$this->assign('title', $post);
My question is:
How can I set a default value/content for (let's say) the title, in order to overwrite if needed ?
Thank you!
Fetch the var. If its not empty, echo it, otherwise echo the default.
$title = $this->fetch('title');
echo !empty($title) ? $title : 'Default';
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.