CakePHP 2.x display map location using address? - cakephp

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"); ?>

Related

Cakephp 2.5 Postlink hidding the model atribute name at the url

I am using a cakephp 2.5 postlink method inside a view file :
$tableRow['Model.modelatribute'] = $this->Form->postLink(
$data['Vehicle']['plate'],
array('controller'=>'somecontroller',
'action' => 'somemethod',
'Model.modelatribute' => base64_encode($data['Vehicle']['plate'])
),
array('confirm' => 'Look at vehicle '.$data['Vehicle']['plate'])
);
I would like not to show the model atribute name on the url bar. After clicking on the link and being redirected, the url shows :
somemethod/Model.modelatribute:vSpEeTIweQ%3D%3D
Can i hide the model atribute name, using postlink method o cakephp 2.5 ?
ThankĀ“s in advance
If you simply want to pass the value of Model.modelatribute as a parameter, just leave off Model.modelatribute in your routing array. If you want to pass the value without occouring in the url you can use the data option of postLink.
echo $this->Form->postLink(
$data['Vehicle']['plate'],
array(
'controller'=>'somecontroller',
'action' => 'somemethod',
base64_encode($data['Vehicle']['plate']) // Routing array without modelname
),
array(
'confirm' => 'Look at vehicle '.$data['Vehicle']['plate'],
'data' => array(
// Data option of postLink method
'Model.modelatribute' => base64_encode($data['Vehicle']['plate'])
)
)
);
Well, you put in there. If you don't want it to be there simply don't put it in the URL. You can alternatively put it into the body of the POST request.
If you're concerned that people can use the model name for something and you want to hide it for that reason, then it is a very bad approach called security through obscurity. Instead you want to ensure that you validate that only values you want are passed and processed. So check your incoming data, always, from everywhere.

Yii2 Fileinput widget initializing after renderAjax

I am completely lost for two days and have no clue how to fix this nonsense!
I use fileinput widget in my page like this:
echo FileInput::widget([
'name' => 'attachment_product[]',
'id' => 'img_products',
'options' => [
'multiple' => true
],
'pluginOptions' => $pluginOptions,
]);
In the same page i have a button that when clicked, reloads the content with renderAjax.
On success i reload the content like this:
$('.content').html(data);
The problem is that the fileInput widget is not being initialized.. I dont know what to do and i get this error:
fileinput_516a5cfe is not defined
As i read here: https://github.com/kartik-v/yii2-widgets/issues/229 and here: https://github.com/kartik-v/yii2-widget-switchinput/issues/14. I need to reinitialize the plugin but I have no clue how to do that... I am lost..
This is by design, A JavaScript file would typically only need loading once so all subsequent requests filter out already included files.
If you want to load it with every request you can add it's path to yii.reloadableScripts yii.js
https://github.com/yiisoft/yii2/issues/10251

Drupal 7 how to apply custom template to my custom form

I have a module, which includes multistep form. I decided to make one of these steps work like this: free times per employee are rendered as html elements, and when element is clicked, Javascript will apply the value to hidden input field.
So I found this tutorial: http://drupal.org/node/1092122 but it didn't work for me, maybe I made a error, maybe not.
My module name is reservation. My template file is named reservation_select_time_week_page.tpl.php and its in the reservation/theme folder.
I have these functions:
function reservation_theme() {
// basic things
$module_path = drupal_get_path('module', 'reservation');
$base = array(
'path' => "$module_path/theme",
);
// define themes
return array(
'reservation_select_time_form' => $base + array(
'render element' => 'form',
'template' => 'reservation_select_time_week_page',
),
);
}
function template_preprocess_reservation_select_time_week_page(&$variables) {
echo "this works!";
}
function template_preprocess_select_time_form(&$variables) {
echo "this works!";
}
I dont know which of those preprocess functions is right (should it be named based on template name or form id?
Anyhow, custom template is not applying.
I also have tried using the:
$form['start_time'] => array('#theme' => 'reservation_select_time_week_page');
I got it working, so that the static html is rendered in template file, but I dont know how I can render the form elements in template file. Using:
drupal_render($form)
caused the form to go infinite loop I think.
Is Drupal even able to handle complex forms and form layouts?

Converting named parameters to GET parameters for pagination at CakePHP 2.2

I am trying to convert named parameters to GET parameters for pagination at CakePHP 2.2 following the instructions given in the documentation but it is not working.
Instead of this:
http://localhost/cake/posts/yourPosts/page:2?url=posts%2FyourPosts
I want this:
http://localhost/cake/posts/yourPosts/?page=2&url=posts%2FyourPosts
The thing is, when i submit a form using GET method, i don't want to retain the current page, and currently, it is doing it by default because it is not a normal param but a named param.
(?url=posts%2FyourPosts is added automatically with the GET method)
I have tried to to this in my view but it stills passing the parameter as a named one:
$this->Paginator->options(array('convertKeys' => array('page')));
echo $this->Paginator->next(' >', array('class' => 'button next right'), null, array('class' => 'next button'));
What am I doing wrong?
you should fix the issue at its source, not cloaking it:
http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#pagination-with-get-parameters
public $paginate = array(
'paramType' => 'querystring'
);
in your controller

Accessing actions with prefixes in cakephp

im still noob with cakephp. I want to access an action with a prefix but im being redirected to my current view. how can i do this? Example:
ihave a function like below:
function admin_getID()
{
some codes here...
}
in my link. i accessed it using this html helper:
$this->Html->url(array('action'=>'getID', 'admin'=>true))
note that currently i dont have any prefix and i want to access the action with a prefix.
the url will be used in jQuery.ajax's URL so in the jquery,
jQuery.ajax({
...
url:"Html->url(array("action"=>"getID", "admin"=>true))?>",
...
});
Thank you!
Since in your file core.php you are using the same prefix, for example:
Configure::write('Routing.prefixes', array('admin'));
You should use:
echo $this->Html->link('link', array('action' => 'getID', 'admin' => true));
This will generate the link /admin/{your_controller}/getID.
For the same Controller, but if you want to display to another controller, you must include the controller parameter in the array.
If you're not using the directive Routing.prefixes as I said above, simply add the admin_getID parameter in action value.
I think you are talking about routing. So for example, if you want to define actions for admin like:
admin_index
admin_edit
admin_view
adn have them accessible by
example.com/admin/index
example.com/admin/edit
example.com/admin/view
This is called routing in CakePHP. You can see how this is done here:
http://book.cakephp.org/1.3/en/view/948/Defining-Routes
Update
You can just do this:
<?php echo $this->Html->link('link', array('controller' => '{CONTROLLER_NAME}', 'action' => 'getID', 'admin' => 'true')); ?>
UPDATE 2
You are not echoing your URL. You need to do this:
jQuery.ajax({ ... url:"<?php echo $this->Html->url(array("action"=>"getID", "admin"=>true)); ?>", ... });
If you are not using PHP to render your jQuery, you cannot use cake to generate your URL, you will have to do it manually:
jQuery.ajax({ ... url:"/admin/CONTROLLER/getID", ... });

Resources