Id like to pass buttons from the cakePHP 2 (note: I'm using Twitter Bootstrap 2.2.1) into an Element in app/View/Elements/Toolbar.ctp
<div class="actions">
<?php echo $this->Html->link(__('New User'), array('action' => 'add'), array('class' => 'btn btn-small',)); ?>
</div>
Above is an example of the button.
Depending on the view, I'd like to pass in different Buttons with different actions.
How do I do that? With Elements, Blocks, requestaction() or what?
The cakephp way doing would look like this
In view
<?= $this->element('toolbar', array('button' => $button_type)) ?>
in element there will be variable called $button available. Note that $button_type variable is also available in element.
That should do it
Related
With Cakephp 4 I would like to display some data. As there is too much data I would like to use pagination only I don't want to reload the whole page, just the part that displays this data. So I created a cell like this:
fileCell.php
public function display() {
$results = $paginator->paginate(
$query,
$this->request->getQueryParams(),
[
'limit' => 20
]
);
}
$paging = $paginator->getPagingParams() + (array)$this->request->getParam('paging');
$this->request = $this->request->withParam('paging', $paging);
$this->set('res', $results);
and I display the pagination in my view like this:
<div class="instances index content">
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
</div>
</div>
Except that by doing so I reload the whole page while I would like to reload only the part concerning the cell, can someone help me?
I am just a beginner at Cake, but I wonder if a finder function in your Controller could take a page parameter?
I don't have an example, but I will soon be doing something similar.
I made a standard ajax call, I create function in my controller. I create view associate corresponding to my element.
In my main view (where I will place my element), I add div :
<div id="test">
</div>
And, in my ajax response I add :
$('#test').html(response);
After that, I manage the pagination of my element normally with cakephp pagination.
I'm trying to render a view that with actions from one view, into another controllers view.
I have a a view called stocks.ctp (using StocksController) that I want to render in home.ctp (HomeController) I thought I could just do <?php echo $this->fetch('../Stocks/stocks'); ?> in home.ctp, but that isn't working.
I've also tried putting <?PHP $this->extend('stocks'); ?> in home.ctp but that just overwrites the entire view and only renders stocks.ctp.
How can I display stocks.ctp inside home.ctp?
This is just an an example: Here is the
<?php $this->start('stocks');?>
<div>
content
</div>
<?php $this->end(); ?>
And here is just and example of the home.ctp view.
<div class="col-3">
<h1>STOCK MARKET WOOOOO</h1>
<?php echo $this->fetch('stocks'); ?>
</div>
<div class="col-3">
<h1>Opinion</h1>
<hr></hr>
</div>
How can I render this properly? I've tried a bunch of solutions that I've found here but nothing has worked yet and I've tried the using cookbook's documentation but no luck. I can't figure out what I'm doing wrong.
You should read about how to create elements in CakePHP documentation.
After create elements, you should be able to use them wherever you want in your application.
Create the element inside View/elements, ex: /View/elements/stocks.ctp
Request it in your home.ctp.
For example:
<?php
echo $this->element('stocks');
?>
The element should be rendered.
Read about it here: Elements
You should put this in your Homecontroller..
$this->render('Stocks/stocks');
In your controllers action do
$this->autoRender = false;
and at the end of your controller action do
$this->render('Stocks/stocks');
I am trying to use CakePHP HTML Linker for the following code
<li class="iAdd"><span>Add Cuisine</span></li>
Since the span tag needs to be inside the a tag. am not able to get the output as need. Any suggestions on how to get it done ?
Disable the escape option in your link code, like so:
<li class="iAdd">
<?php echo $this->Html->link(
'<span>Add Cuisine</span>',
array('action' => 'add'),
array('escape' => false) // This line will parse rather then output HTML
); ?>
</li>
you can always use normal html in links:
$this->Html->link('<span>'.h($text).'</span>', array('action'=>'add'), array('escape'=>false));
I have built an cakephp site that lets users upload files, all works fine but I would like to show a image saying "file uploading" or something while it is uploading. Now I know that I should use the $ajax->form helpers but I can not seem to get this to work. Can some one point me in the right direction please
<?php echo $ajax->form(array('type' => 'post',
'options' => array(
'model'=>'Upload',
'update'=>'post2',
'action' => 'add',
'confirm' => 'Are you sure?',
'indicator' => 'loading',
'before' => '$("#post2").html("Wait a moment")'
)
));
?>
<fieldset>
<legend><?php __('Add Upload');?></legend>
<?php echo $form->input('title'); ?>
<div id="formUpdate">
</div>
<?php echo $form->input('Uploaded.uploaded_file', array('type' => 'file', 'label' => 'Upload file')); ?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
<div id="post2"></div>
Ok, if you don't want to use Ajax upload solution, then it could be achieved with simple javascript. I would explain how to do with jQuery, but you can achieve with any library or pure javascript too.
So, create a hidden div containing your please wait message i.e.:
<div id="wait">File is uploading please wait</div>
Then on the submit button of your form attach following function:
function pleaseWait(){
$('#your_form_id').hide();
$('#wait').show();
}
This basically would hide the form and will display the wait container. Once the file has been uploaded, the page will be redirected so, you don't need to worry how to show the form again.
I've did it on my project and it was working pretty well.
How can I create submit button, and define custom title on it, together with custom class style?
You could use either submit() or button() methods of the Form helper instead of the end() method. For example:
echo $this->Form->submit(
'Send',
array('class' => 'custom-class', 'title' => 'Custom Title')
);
Don't forget to close the form. You can do it by calling the end() method without any arguments.
echo $this->Form->end();
Also remember, you can always do it old school
I prefer to use $this->Form->end( ); without arguments and build my own submit buttons and markup. It's easy
<div class="buttons clearfix">
<button type="submit" class="positive">
<span class="icon-wrapper"><img src="path/to/tickmark.png" alt="" title="" /></span>
Save Item
</button>
</div>
I would also tell you to experiment with the $this->Form->input('Model.field', 'options' => array( array('type' => 'button'))); - particularly the before, between, after, and class options. You can use the helper to create <input type="button" /> elements with a good amount of flexibility.
you can create costum submit by this code
echo $this->Form->submit(
'Submit',
array('div' => false,'class' => 'urclass', 'title' => 'Title')
);
This is enough:
echo $this->Form->submit("Custom message");
Also as #Mike suggest close the form with
echo $this->Form->end();
Or you can combine both with:
echo $this->Form->end("Custom Message");
I created a custom button using an image in my under app/webroot/img that uses inline style for specifying size and changing the position to center
$options=array('type'=>'Make secure payment', 'type'=>'image', 'style'=>'width:200px; height:80px; display:block; margin-left:auto; margin-right:auto;');
echo $this->Form->submit('/img/axiaepaysecurebuttongray_med.png', $options);
echo $this->Form->end();
For CakePHP 2.x, you can use
$options = array(
'label' => 'Update',
'div' => array(
'class' => 'glass-pill',
)
);
echo $this->Form->end($options);