Cakephp sizing a new window link - cakephp

Hi all creating a link that when you click it, it opens a new window. I was wondering if it's possible to restrict the size of the window opening?
this is the code I have for the link that opens the window
<?php echo $this->Html->link(
$this->Html->image($help, array(
"alt" => "eBox")),
'/accounts/help', array('target'=>'_blank', 'escape'=>false)); ?>

You can do this, but only with Javascript.
Raw code would be something like:
Text Link
The only parameters you really need are width and height, but you might find the others useful too. If not, just delete them. If the user doesn't have javascript, it'll just open the link normally.
To do it with html helper, pass your javascript through to the onClick array key:
<?php echo $this->Html->link(
$this->Html->image($help, array(
"alt" => "eBox")),
'/accounts/help', array(
'target'=>'_blank',
'escape'=>false,
'onClick'=>"window.open('/pages/home', 'windowname','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=300,height=290'); return false;"
)); ?>
PS - you can read up on the window.open method here: http://www.w3schools.com/jsref/met_win_open.asp

Related

How to give id to an image in CakePHP?

I'm inserting an image in my template file as
<?php echo $this->Html->image('profile_picture.png', array('alt'=>'frame partner avatar'), array('id'=>'framePartnerAvatar')); ?>
Now I'm trying to give style to this image by using the id mentioned, but on checking through Firebug only source and alternate name is visible. Image id is not coming there.
You have to use the correct syntax:
<?php echo $this->Html->image(
'profile_picture.png',
array(
'alt'=>'frame partner avatar',
'id'=>'framePartnerAvatar'
)); ?>
See HtmlHelper::image()
According to the documentation the method used to create images requires two parameters. The first one being the source link and the second one being the options parameter
$this->Html->image('cake_logo.png', ['alt' => 'CakePHP']);
Your code should be something along the lines of this
$this->Html->image('profile_picture.png', array(
'alt'=>'frame partner avatar',
'id'=>'framePartnerAvatar')
);
$thumb_img = $this->Html->image('yourimage.png',array('alt'=>'yoursite.com','id'=>'yourId'));
Please ensure that all HTML attributes such as alt, id, class etc needs to be written within a single array, and not multiple arrays.
<?php echo $this->Html->image('profile_picture.png', array(
'alt'=>'frame partner avatar',
'id'=>'framePartnerAvatar'
)
); ?>
This will certainly generate the following HTML:
<img src="/img/profile_picture.png" alt='frame partner avatar' id='framePartnerAvatar' />
Peace! xD

Save associated Model data before Form submission

I have a polymorphic attachment model between Article and Image (alias for Attachment model) ala https://github.com/josegonzalez/upload. Article hasMany Image. Image is an Attachment.
When the form is submitted via the Article form's save button, everything saves properly, including associated models.
However, I have set up a dynamic display of attached images so that the user can choose which one to use for the article's preview before saving the article. The dynamic image display works (proved by deleting row in phpMyAdmin), but I cannot figure out how to upload and save the associated Image that has been selected without pressing the submit button. I'd like to upload the image immediately upon selection (or upon a button press that does not submit the article, too!
Here is the relevant form section, and the script that eventually results in the display of all associated Images.
<div id='imagesControl'>
<?php
//TODO gotta make this happen live
echo $this->Form->input('Image.0.attachment', array('type' => 'file', 'label' => 'Image'));
echo $this->Form->input('Image.0.model', array('type' => 'hidden', 'value' => 'Content'));
echo $this->Form->input('Image.0.foreign_key', array('type' => 'hidden', 'value' => $id));
echo $this->Form->input('Image.0.id', array('type' => 'hidden')); //Thought this would help
?>
<div id='attachedImages'>
</div> </div>
<script>
$(document).ready(function() {
$('#imagesControl').change(function() {window.alert("sometext");
$("#attachedImages").load('../imageDisplay/<?php echo $id ?> #attachedImages',
{id: $(this).attr('id')});
})
.change();
});
</script>
Notably, in the view file '../imageDisplay' that gets rendered, $this->data only contains the div id sent via $(this).attr('id'). I cannot find a variable, anywhere, that contains the file I chose in the input section before the form saves (the file I'm trying to upload and save). It's apparently there, because it does save using $this->Article->saveAll() automagic.
However, I cannot even begin to guess where / when / how I can upload the image and add a row to the attachments table containing the new image's data without submitting the article. I've been stuck for days.

CakePHP 2.x display map location using address?

I have CakePHP website I want to display Google map and marker in given address on my CakePHP application.
Is there any plugin available to display address in Google map.
You probably did not even try to google.
Or you would have stumpled upon at least a dozen plugins/solutions.
Check this one out:
http://www.dereuromark.de/2010/12/21/googlemapsv3-cakephp-helper/
// include jquery js
$this->Html->script('jquery', array('inline' => false));
// include the google js code
$this->Html->script($this->GoogleMapV3->apiUrl(), array('inline' => false));
// echo the div container to display the map in
echo $this->GoogleMapV3->map(array('div'=>array('height'=>'400', 'width'=>'100%')));
$options = array(
'lat' => 48.95145,
'lng' => 11.6981,
'title' => 'Some title', // optional
'content' => '<b>HTML</b> Content for the Bubble/InfoWindow' // optional
);
$this->GoogleMapV3->addMarker($options);
// finalize js
$this->GoogleMapV3->finalize();
// Make sure you got `echo $this->Js->writeBuffer(array('inline' => true));` somewhere in your layout then
If you do not have the lat/lng yet, you can either geocode via JS at runtime or use Cake to do so: http://www.dereuromark.de/2012/06/12/geocoding-with-cakephp/
You can also use CakePHP-GoogleMapHelper that will geocode the address on the fly and add it to your map. You would do something like this: (see more details on the link shared)
<?= $this->GoogleMap->addMarker("map_canvas", 1, "1 Infinite Loop, Cupertino, California"); ?>

how to create form in cake php

I am very new in cake php, i want to know how to create form in cake php,please describe,when we go to create a form then what i have to do,like create model and controller everything
In the view file, something like this would work:
<?php
echo $this->Form->create();
echo $this->Form->input('firstname', array('label' => 'Enter your first name:'));
echo $this->Form->input('email', array('label' => 'Enter your email address:'));
echo $this->Form->input('password', array('label' => 'Enter your password:'));
echo $this->Form->end('Save');
?>
In your controller:
if($this->request->is('post')){
$this->User->save( $this->request->data );
}
You can apply some sort of validation in your model, look in the documentation for that.
Best option to learn about cakephp is it's own doc book
But I'm providing you some basic code to create form :
$this->Form->create('ModelName');
$this->Form->input('ModelName.fieldname', array('type'=>'text', 'label'=>'Modified-Name'));
$this->Form->end(__('Submit'));
Here array('type'=>'text'...): type shows which type of input field you want.
(...'label'=>'Modified-Name'): By default it shows field text as fieldname but by using 'label' you can modify your field text.
$this->form->create('controlpage',
array(
'action'=>'controll',
'class'=>'class',
'enctype' => 'multipart/form-data',
'onsubmit'=>'return valid()'
));
Block quote
Create form in html save it as ctp
Block quote
And call it in view. enter code hereUse cake php book to read further.

CakePHP - how to use $html->link inside an element

How can I use $html->link from within an element?
Thanks,
Tee
In both 1.2 and 1.3,this should work:
echo $html->link('linkname',array('controller'=>'somecontroller','action'=>'someaction/somearguments'));
Update
The html helper has changed a little in version 2.x.An example from the cook book
echo $this->Html->link('Enter', '/pages/home', array('class' => 'button', 'target' => '_blank'));
The new version of Cakephp has easier ways to work with html->links, definitely you can convert links into buttons.
If you want using bootstrap or some css however for normal links you can use:
<?= $this->Html->link ('Sometexthere', ['controller' =>'myController', 'action' =>'myAction']); ?>

Resources