I have to set request data which is in the form of HTML in CAKEPHP.
Request Data is :
<div class="row">
<div class="span6">
<h3>Company Name</h3>
Company Address
</div>
<div class="span6">
<h5>INVOICE</h5>
</div>
</div>
How to set this in controller? $this->set() is not working.
$this->set('html', $this->request->data);
View :-
<?php echo $html; ?>
In case you are talking about data to fill form
$this->request->data = $this->YourModel->find();
should do the trick.
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?
I am working in angularjs application, i have used ng-repeat in my application but i need to insert images in between every ng-repeat loop dynamically.
Is it possible to inject image inbetween every ng-repeat.
sample xml file
`<?xml version='1.0' encoding='UTF-8' ?>
<revista>
<notas>
<banner>No</banner>
<bannerFuente></bannerFuente>
<bannerURL></bannerURL>
<copete>Editorial</copete>
<titulo>Se armó en grande</titulo>
<seccion>Opinión</seccion>
</notas>
<notas>
<banner>No</banner>
<bannerFuente></bannerFuente>
<bannerURL></bannerURL>
<copete>Perfiles de clientes</copete>
<titulo>¿Quién se llevó mi negocio?</titulo>
<seccion>Opinión</seccion>
</notas>
<notas>
<banner>No</banner>
<bannerFuente></bannerFuente>
<bannerURL></bannerURL>
<copete>Gestión empresarial</copete>
<titulo>Gestión para pequeños negocios</titulo>
<seccion>Opinión</seccion>
</notas>
</revista>`
js file
$http.get('sample.xml').then(function(response)
{
var dom = response.data;
$scope.posts = dom.revista.notas;
})
html file with ng-repeat and swiper
<div class="swiper-container" ng-controller='MainCtrl'>
<div class="swiper-wrapper">
<div class="swiper-slide" ng-repeat="key in posts">
<div class="mag_content_wrap con_style1">
<div class="cls_favorite_sec editorial_page1">
<h2>{{key.seccion}}</h2>
</div>
<div class="cls_favorite_sec editorial_page">
<div class="cls_inner1 img_r">
<p class="img_con">
<img src="Imagenes/{{key.imagen}}" />
</p>
</div>
<div class="cls_inner2 editorial_page2">
<h2>{{key.copete}}</h2>
<h3>{{key.titulo}}</h3>
</div>
</div>
</div>
</div>
</div>
</div>
In the above code ng-repeat shows three pages properly, but i need to load image inbetween every page after swipe. If i swipe first content it should shows image and if i swipe image it shows second content and vice versa.
In my layout cakephp I have 2 divs:
<div id="header">
</div>
<div id="sideBar">
</div>
The question is, standing on a view,
for example index.ctp, how can I call an element inside the div sidebar for exemple?
So how can I add an element inside a div created elsewhere?
You can use the new and powerful view blocks:
http://book.cakephp.org/2.0/en/views.html#using-view-blocks
Just like this:
<div id="sideBar">
<?php echo $this->element('sideBar'); ?>
</div>
If you want to pass params:
<div id="sideBar">
<?php echo $this->element('sideBar', array('param1' => $param1)); ?>
</div>
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.
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.