issues using code after exporting mssql to sqllite - perl

I am trying to shift a website from using a MS-SQL database to SQLite. I have therefore exported the MS-SQL database to SQLite and connected it successfully with Dancer, the lightweight Perl web framework which uses Template Toolkit.
I now have an issue with the FOREACH loops. Data is being passed as usual - as tested with the debug to_dumper($test) statement - but TT does not show it. Are you aware of any differences between MS-SSQL and SQLite? Other FOREACH loops also appear to have the same non display of data issue.
Any ideas are much appreciated!
a tail on the data passed is:
{
'OneLiner' => 'Cruise on the Kerala backwaters',
'Meta_Descr' => 'Get inspired by the trip ideas on our Traveller\'s Palm website. We are passionate about India and will be delighted to help you in designing your own tailor-made tour.',
'PageName' => 'Popular Tours',
'Introduction' => 'Tried and tested by thousands of clients over thirty years, these tours are the classics that always deliver. Tweaked and perfected based on our clients\' feedback these tours give you that perfect introduction to India or are the quickest way to travel between your old favourites. Rajasthan, Kerala, Goa and North India all feature on these tours and with good reason.
We\'d also be happy to make any personalized changes or additions to these itineraries if you so choose and add your personal twist to these well-loved highlights.',
'Meta_Title' => 'Popular Tours - Experience India | Traveller\'s Palm',
'url' => 'popular-tours',
'Themes_id' => 7,
'Meta_Keywords' => 'popular holidays india, tailor-made popular india tours, popular india custom tour'
},
{
'Meta_Title' => 'Romance - Experience India | Traveller\'s Palm',
'Introduction' => 'Muslin draped four poster bed or a gently moving boat in the tropical backwaters? Tracking a tiger or exploring a working farm? Your romantic getaway can be what you want it to be; a sybaritic time with your beloved or an active and adventurous time shared with your spouse.',
'Meta_Descr' => 'Get inspired by the trip ideas on our Traveller\'s Palm website. We are passionate about India and will be delighted to help you experience the romance of travel in India.',
'PageName' => 'Romance',
'OneLiner' => 'Looking for a romantic getaway',
'Meta_Keywords' => 'romantic holidays india, tailor-made india romantic holidays, india honeymoon tour',
'Themes_id' => 12,
'url' => 'romance'
}
]; in /home/user/webapps/travelo/lib/xxx/MemcacheDB.pm l. 1483
the memcached query is identical as used with the MS-SQL based site:
sub themes {
return memcached_get_or_set('themes',sub {
my $qry = "SELECT pagename,introduction,url, oneliner,
meta_title,meta_descr,meta_keywords,themes_id
FROM themes";
my $test = database('sqlserver')
->selectall_arrayref( $qry, { Slice => {} } );
debug to_dumper($test);
return $test;
});
}
The relevant html section in TT is:
<ul class="slides image-box style1">
[% FOREACH theme in themes %]
<li>
<article class="box">
<figure>
<a class="hover-effect" title="[% theme.title %]" href="[% request.uri_base %]/destinations/[% country %]/[% THEMES %]/[% theme.url %]">
<img width="270" height="160" alt="" src="[% IMAGE %]/themes/themes_[% theme.themes_id %].jpg" />
</a>
</figure>
<div class="details">
<h4 class="box-title">[% theme.pagename %]</h4>
</div>
</article>
</li>
[% END %]
</ul>

Related

Laravel: View not included in email content

I am using the BeautyMail package to send an email, which is sent successfully via stmp.gmail.com. I found out that the content of emails.welcome (welcome.blade.php) is not included, the email delivered is empty.
Below is my code;
$data = array(
'LastName' => 'ABC Widget', // Company name
'senderName' => 'ABC Widget', // Company name
'reminder' => 'You’re receiving this because you’re an awesome ABC Widgets customer or subscribed via our site',
'unsubscribe' => null,
'address' => '87 Street Avenue, California, USA',
'twitter' => 'http://www.facebook.com/abcwidgets',
'facebook' => 'http://twitter.com/abcwidgets',
'flickr' => 'http://www.flickr.com/photos/abcwidgets'
);
Mail::send('emails.welcome', $data, function($message)
{
$message->from( 'johnny#gmail.com', 'John Doe' );
$message->to('Suzanne#yahoo.com', 'Suzanne Doe')->subject('Testing Messages');
});
VIEW
#extends('beautymail::templates.widgets')
#section('content')
#include('beautymail::templates.widgets.articleStart')
<h4 class="secondary"><strong>Hello World</strong></h4>
<p>This is a test</p>
#include('beautymail::templates.widgets.articleEnd')
#include('beautymail::templates.widgets.newfeatureStart')
<h4 class="secondary"><strong>Hello World again</strong></h4>
<p>This is another test</p>
#include('beautymail::templates.widgets.newfeatureEnd')
#stop
No error was reported. What I am doing wrong?
Trying removing the BeautyMail package and testing it. When I tried using the BeautyMail package, I had a similar problem.
Beautymail have Ruby dependencies. I do think one of them fails which renders the empty email.
This issue has more details:
https://github.com/Snowfire/Beautymail/issues/2
Remove the inliner found in the service provider to remove the ruby dep.

Accessing stacked data structures with HTML::Template::Compiled

To display a task dashboard on the web I take information from a file with Perl, store that in a stacked hash and send it to HTML::Template::Compiled.
There I can only access the key of the hash but no further data.
Here is what I wrote in Perl
my $template = HTML::Template::Compiled->new(
filename => '../templates/task_dashboard.tmpl',
case_sensitive => 1,
search_path_on_include => 1,
loop_context_vars => 1,
use_query => 0,
default_escape => 'HTML',
);
$template->param(
TIME => $time,
VERSION => $version,
REPORTDAT => $reportdat,
INFOS => \%information,
);
print $template->output();
The hash %information looks like this:
%informmation{key} = ($RefToArrayOfHashes1, $RefToArrayOfHashes2, $Skalar1, $Skalar2);
Within HTML::Template::Compiled I want to loop through the hash %information and subsequently through its content (like Data::Dumper).
I wrote this in the template file:
<%each INFOS %>
<h2><%=__key__ %></h2>
<table>
...loop through RefToArrayOfHashes1
</table>
<table>
...loop through RefToArrayOfHashes2
</table>
<p>Skalar1, Skalar2</p>
<%/each %>
To access the keys of %information is not a problem, but I don't know how to access the lower levels of the data structure.
I read some things about to use Dot but still don't get how to do it.
Can anybody help me by giving an example?

PHPTAL: how to dump an object to see all properties

I have to modify the PHPTAL template below by adding another field, "location"
<tal:block tal:repeat="contact Model/contactList">
<div class="contactCell">
Name: <span content="contact/name">contact name</span><br/>
Number: <span content="contacy/number">2374687234</span><br/>
<-- THIS NEEDS ADDING-->
Location: <span content="contact/location">contact's location</span>
</div>
</tal:block>
My problem is that I don't know what methods and properties are available in the model and I don't want to read the PHP code to trace this either. I would like to be able to dump out all the properties of the model from within the template so it's easy to see if the property I need is already available or whether I have to ask the backend dev to make it available. Something like this would be good.
<div class="debug panel">
<tal:dumpObject Model/contactList>
</div>
which would then produce something like this in my HTML output:
<div class="debug panel">
contact Array
[
{
[name] => John Smith
[number] => 374862378
[address] => 22 Acacia Avenue
[location] => London
},{
[name] => Billy Bragg
[number] => 384567365
[address] => 10 Downing Street
[location] => London
},
...
]
</div>
This way I would be able to immediately see what I can use and what I need to request from other devs.
You can get pretty far with:
<pre tal:content="php:print_r(object, true)"/>
if the object is a plain array or a stdClass object.
However, PHPTAL can also read object's methods and invokes magic __get() methods, so if the object is from some fancy ORM it may not be possible to list all properties that would work.
You can use var_dump inside PHPTAL as well:
<pre tal:content="php:var_dump(object)"/>

Set the default value of a Facebook Registration Plugin "Text Field"

Good afternoon,
I'm now use the Registration plugin of Facebook and I would to set the default value of a field in text type.
But I don't know if it's possible ? How to set a default value of a text field in PHP and in the plugin ? Thank's for your Help !
<iframe src="https://www.facebook.com/plugins/registration?
client_id=APP_ID&
redirect_uri=[...]&
fields=[{'name':'name'},
{'name':'last_name'},
{'name':'first_name'},
{'name':'birthday'},
{'name':'gender'},
{'name':'email'},
{'name':'telephone', 'description':'T\u00e9l\u00e9phone', 'type':'text', 'default':'sith'},
{'name':'portable', 'description':'Portable (facultatif)', 'type':'text','no_submit':true},
{'name':'fax', 'description':'Fax (facultatif)', 'type':'text','no_submit':true},
{'name':'adresse','description':'Adresse','type':'text','default':'truc'},
{'name':'adresse_suite','description':'Adresse (suite)','type':'text','no_submit':true},
{'name':'code_postal','description':'Code postal','type':'text'},
{'name':'ville','description':'Ville','type':'text'},
{'name':'pays','description':'Pays','type':'select',
'options':[...]},
{'name':'password'},
{'name':'captcha'},
{'name':'abonnement','description':'Re\u00e7evoir la Newsletter','type':'checkbox'},
{'name':'stop_pub','description':'Re\u00e7evoir des offres marketing et bons d\'achat','type':'checkbox'},
{'name':'offre_sortir','description':'Re\u00e7evoir des bons plans Sortir Malin dans votre r\u00e9gion','type':'checkbox'},
{'name':'offre_partenaire','description':'Offres publicitaires de la part d\'autres partenaires','type':'checkbox'}]"
scrolling="auto"
frameborder="no"
style="border:none"
allowTransparency="true"
width="100%"
height="850"
onvalidate="validate">
</iframe>
Sorry for my bad English, I'm French ! =)
According to the documentation, the default parameter is only applicable to the type:select and type:checkbox fields, not the text fields ): So you're kinda screwed there.
For reference:
default only applies to select and checkbox fields http://o7.no/K5jDj0
However, if it were me, I'd build a complete array of the options I wanted to send, and json_encode them in one go instead of defining them directly inside the <iframe> tag, for example:
<?php
$regOptions = array(
array('name' => 'name'),
array('name' => 'last_name'),
array('name' => 'birthday'),
//the other fields
array('name' => 'telephone',
'description' => 'T\u00e9l\u00e9phone',
'type' => 'text'
),
//the other fields
);
?>
//Then in your iframe:
<iframe src="https://www.facebook.com/plugins/registration?
client_id=APP_ID&
redirect_uri=[...]&
fields="<?= urlencode(json_encode($regOptiosn)); ?>
scrolling="auto"
frameborder="no"
style="border:none"
allowTransparency="true"
width="100%"
height="850"
onvalidate="validate">
</iframe>
This allows you to leverage json_encode and urlencode to define your fields without fear of the browser mucking up the request due to wonky strings.
As for some fields being optional, required, check out the advaned registration button features in the doucmentation. FB affords you a few ways to validate your form, which should allow you to block form submission when fields are invalid/not filled out.

CakePHP: allowing database update with button click

I have a product search page with the form below. The search result is displayed on the same page with search bar at the top.
echo $this->Form->create('Searches', array('action'=>'products', 'type' => 'get', 'name' => 'textbox1'));
echo $form->input($varName1, array('label' => false));
echo $form->end('Locate');
I also have a little box next to the search result that allows (it doesn't work yet) the user to flag using checkboxes a product and accordingly update its database (table products and using model Product) with a button click. Note that I have a Searches controller for this search page.
<form method="link" action="/myapp/product/test_update_db>
<label><input type="checkbox" name="flag1" <?php echo $preCheckBox1; ?>>Flag 1</input></label>
<label><input type="checkbox" name="flag2" <?php echo $preCheckBox2; ?>>Flag 2</input></label>
<input type="submit" value="Update">
</form>
I'm having difficulty with this approach figuring out how to perform this check-box-and-DB-update routine. I'm getting to the link I'd like to go (/myapp/product/test_update_db), but I don't know how to take variables flag1 and flag2, along with row ID of this result ($results['Product']['id'])) to the new page.
Could someone guide me on how to perform this neatly? Is this general approach correct? If not, what route should I be taking? I'd prefer not to use javascript at this time, if possible.
EDIT: I think I can make this work if I use the URL for passing data.. but I'd still like to know how this could be done "under the hood" or in MVC. I feel like I'm hacking at the CakePHP platform.
UPDATE: So, I ended up using the URL parameters for retrieving information pieces like flag1 and flag2. I'm still looking for an alternative method.
To see where your is-checkbox-checked data is located, do the following in your controller:
// Cake 2.0+
debug($this->request->data);
// previous versions
debug($this->data);
If you want to pass data to your search controller from the current page, you can always add the data to your form:
$this->input
(
'Product.id',
array
(
'type' => 'hidden',
'value' => $yourProductId
)
);
I ended up using information embedded in the URL for getting submission data. Something like below..
In Products controller, when the form with flag1 and flag2 are submitted:
public function test_update_db() {
// Get variables from URL, if any, and save accordingly
$result = $this->Product->updateProduct($this->params['url'], 'url');
if ($result) {
$this->Session->setFlash('Successfully updated!', 'default', array('class' => 'success'));
$this->redirect($this->referer());
}
else {
$this->Session->setFlash('Update was unsuccessful!', 'default', array('class' => 'error'));
$this->redirect($this->referer());
}
}
This works for doing what I needed to do. I feel like there's a more proper way to do this though.
if ($result) {
$this->Session->setFlash('Successfully updated!', 'default', array('class' => 'success'));
$this->redirect($this->referer());
}