I want to know how to fetch request data by postlink in cakephp 2.0.
echo $this->Html->div('col-md-12', $this->Form->postLink(__($a['b']['name'].'abc'), array('controller' => 'abc', 'action' => 'xyz', $a['b']['slug'], $a['b']['id']), array($a['b']['id'])));
In output I want value for '$a['b']['slug']'.
i.e. pr($a['b']['slug']);
o/p : xyz
Thanks in advance.
There is no way(as per my knowledge) but you can still do it another way using javascript,
<FORM METHOD="POST" NAME="postForm" action="/action_page/55?data=Your_data" hidden>
</FORM>
<?php echo $this->Html->link(
'Enter',
['onClick' => 'document.postForm.submit();return false']); ?>
As per my knowledge, this is an alternative solution to your question. I think there are no direct ans to your ques.
Related
Hello CakePHP friends.
May I have your suggestion that how can I generate a link in a view,
which is having "?" => [] but will not clear the original param in the URL that the user is browsing?
For example,
<?= $this->Html->link("Blue", ["?" => ["color" => "blue"]]) ?>
generates a link for passing param in URL like ?color=blue
Let say, the user clicked this link, and I want to provide him another link to add 1 or more conditions.
<?= $this->Html->link("Circle", ["?" => ["shape" => "circle"]]) ?>
generates a link like ?shape=circle.
But I hope it will be: ?color=blue&shape=circle.
Please help. Thank you. You can just write in answer if you have one.
you can find your query params in
$this->request->query
so you can use array_merge
$query = array_merge($this->request->query, ["shape" => "circle"]);
echo $this->Html->link("Circle", $query)
You just need to combine your two ? arrays:-
<?= $this->Html->link("Blue Circle", ["?" => ["color" => "blue", "shape" => "circle"]]) ?>
I am making blog and url route is like this-
Router::connect('/blog/c/:catid/*',
array('controller' => 'blogarticles', 'action' => 'index'));
it works well with url as- /blog/c/3/other-articles
but when i use paginator in view as
echo $this->Paginator->numbers();
it generates url as- /blogarticles/index/other-articles/page:2
What changes should in make in paginator to generate proper url.
Please suggest possible solution , Thanks in advance
This should solve your problem:
$this->Paginator->options(
array(
'controller' => 'blog',
'action' => 'c',
$catid,
$title
)
);
The trick is to pass blog as the controller and c as the action, and all other variables (NOT LIMITED TO $catid and $title) as additional parameters, sequentially!
NOTE: I assumed here that you have "set" $catid and $title from your Controller, to the current "category id" and "title" respecting. I also assumed that your URLs are always in the format: /blog/c/:catid/:title
You may also want to view my answer to a similar question: https://stackoverflow.com/a/25097693/2862423
What you want is to set the options for the PaginatorHelper for that view:
<?php $this->Paginator->options(array('url' => '/blog/c/3/other-articles')); ?>
CakePHP Book Section on the PaginatorHelper Options Function: http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#modifying-the-options-paginatorhelper-uses
Hello you coders out there,
I want to do an event chaining with the Js helper but can´t figure out how to do that with the cookbook.
Scenario:
I have an input field, which is fired onkeyup with ajax. That works fine.
The goal:
The ajax call should be fired after putting 3 digits into the field, not everytime.
My thoughts:
Maybe the chaining of the helper could get me out. I thought the return true would tell the helper to go on, otherwise do nothing. But I didn´t find any info. My code so far:
<?php $check = "
if($(this).val().length >3){
return true;
};"; ?>
<?php echo $this->Js->get('#ajaxSearchSCourier')->event('keyup', $check)->request(
array('controller'=>'Posts', 'action'=>'index'),
array(
'update' => '#erfolgreich_ajax',
'before' => $before,
'success' => $success,
'async' => true,
'dataExpression' => true,
'method' => 'post',
'data'=>$this->Js->serializeForm(array('isForm'=>'false', 'inline'=>'true'))
)
);
?>
I hope you have an idea. Many thanks in advance,
Karl
Forget the JsHelper and write js code yourself. Check my related answer here.
Can anyone provide either a method of using the following code that doesn't result in HTML special characters being used in place of the single quotes, or an alternative way to produce the intended result?
<?php echo $this->Html->link(
'View',
$row['view'],
$options = array(
'onMouseOver'=>'setHelp(\''.$row['id'].'\')'
)
);
?>
The result looks like:
<li>
<a href="--url--" onMouseOver="setHelp('--js_param--')">
</li>
Clearly I am doing this wrong. But the Cake API seems to suggest that HtmlHelper's link() method is the go-to for javascript-ready links. Help?
<?php echo $this->Html->link(
'View',
$row['view'],
array(
'onMouseOver'=>'setHelp(\''.$row['id'].'\')',
'escape' => false
)
);
?>
I think your code should work, but you can force Cake not to escape the output:
echo $this->Html->link(
'View',
$row['view'],
array(
'onMouseOver'=>'alert(\''.$row['id'].'\');',
'escape' => false
)
);
How about using pure html?
<li>
<a></a>
</li>
They really do suggest use always if possible cake tags and all(following the conventions), but sometimes is not wrong to use common html to surpass a prob...
When I choose an image and push upload, I get this error in my controller:
Notice (8): Undefined index: File [APP/controllers/garage_car_images_controller.php, line 22]
I've also noticed that the $form->create line shown below does NOT generate form code in the inspected html. This is VERY weird.
Any ideas how to fix this? Thanks!
My view code:
<div class="title_plate">
<h1 id="title_plate_header">add image</h1>
</div>
<div id="overlay_content">
<?php
echo $form->create('GarageCarImage', array('controller' => 'garage_car_images','action' => 'add', 'type' => 'file'));
echo $form->file('File');
echo $form->hidden('garage_car_id', array('value' => $this->params['pass'][0]));
echo "<br><br>";
echo "Make this image the default? " . $form->input('default', array('type' => 'select', 'label' => false, 'options' => array('0' => 'No', '1' => 'Yes')));
echo "<br>";
echo $form->submit('Upload');
echo $form->end();
?>
</div>
My controller code:
if (!empty($this->data) &&
is_uploaded_file($this->data['GarageCarImage']['File']['tmp_name'])) {
$fileData = fread(fopen($this->data['GarageCarImage']['File']['tmp_name'], "r"),
$this->data['GarageCarImage']['File']['size']);
$this->data['GarageCarImage']['type'] = $this->data['GarageCarImage']['File']['type'];
$this->data['GarageCarImage']['user_id'] = $this->Auth->user('id');
$this->GarageCarImage->save($this->data);
}
Are you sure it doesn't generate the form code? If it didn't, I don't think you would even be able to try and submit a form. I believe submitting the form occurs because you seem to issue a request for /garageCarImages/index -- to me, that says that the form is getting generated properly.
If indeed that is the case, you should just change the value of the first parameter to the name of the controller that you want the code to execute in. For me, typically, I use an Attachment controller to do this, so I would put:
echo $form->create( 'Attachment', array(...) );
Your situation will depend on where the code is located to process the upload. Most likely it's the ImageController (guessing here...), but I'm not sure without knowing more details of your system.