ZEND: Return HTML as string using Render? - zend-framework

I have:
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$this->render("voucher-list");
The problem is, when I execute:
$this->render("voucher-list");
It actually prints the information to screen. I want to return the data as an HTML string. This DOES NOT work:
$htmlcontent = $this->render("voucher-list");
How would I go about returning this information as a string?

If you want to send the data into JSON format then you need to make the array of data and use the following code to send the data:
$data = array(3,4,'test', 'my-name' => 3,4); //suppose this is your data
$this->_helper->viewRenderer->setNoRender(true);
$this->view->layout()->disableLayout();
echo Zend_Json::encode($data);
And you will get the data in JSON format.
See this: Zend Framework JSON Output

Related

How to convert mapped variable into base64 string using Mirth

I have:
Raw xml filled by a select query.This xml transformed into a HL7
message
One of the tags of this xml represents a clob column from a table in
the database
I mapped this data (from edit transformer section) as a variable.
Now I am trying to convert this variable into a base64 string then
replace it in my transformed hl7 message.
5.I tried this conversion on a destination channel which is a javascript writer.
I read and tried several conversion methods like
Packages.org.apache.commons.codec.binary.Base64.encodeBase64String();
I have got only error messages like :
EvaluatorException: Can't find method org.apache.commons.codec.binary.Base64.encodeBase64String(java.lang.String);
Code piece:
var ads=$('V_REPORT_CLOB');
var encoded = Packages.org.apache.commons.codec.binary.Base64.encodeBase64String(ads.toString());
It is pretty clear that I am a newbie on that.How can I manage to do this conversion ?
Here is what I use for Base64 encoding a string with your var substituted.
//Encode Base 64//
var ads = $('V_REPORT_CLOB');
var adsLength = ads.length;
var base64Bytes = [];
for(i = 0; i < adsLength;i++){
base64Bytes.push(ads.charCodeAt(i));
}
var encodedData = FileUtil.encode(base64Bytes);

split values of couch db result

I want to split the values selected from couch db in gwt according to a particular id. I tried to use the String tokenizer but couldn't found something useful. the result returned from couch db is in the following format:
{"_id":"2","_rev":"1-717f76046030a683687ace9ac8f7bdbf","course":"jbdgjbj","passwd":"rty","phone":"24125514444","clgnme":"bjfbjf","address":"jbjfbjb","name":"meenal","cpasswd":"rty","user":"2","fname":"jfbg"}
I just want to get the values and set them in textboxes.
how to do it?
try this ...
Session studentDbSession = new Session("localhost",5984);
Database studentCouchDb = studentDbSession.getDatabase("student");
System.out.println("select");
Document d = studentCouchDb.getDocument(input);
if(d.containsKey("FirstName")){
fname=d.getString("FirstName");//fname is variable
}
if(d.containsKey("LastName")){
lname=d.getString("LastName");//lname is variable
}
if(d.containsKey("Address")){
add= d.getString("Address");//add name is variable
}
finally concatenate all strings and return to client...
all=fname+" "+lname+" "+add;
return all;
This looks like JSON. You can parse it using JSONObject:
JSONObject obj = new JSONObject(yourString);
String course = obj.getString("course");

how to parse SMValue to String array

I am just getting familiar with the StackMob server side custom code sdk and i am trying to get a relationship field and iterate through it in the form of a String array. How do i do that ? is it possble to iterate through it without parsing it into an array?
DataService ds = serviceProvider.getDataService();
List<SMCondition> query = new ArrayList<SMCondition>();
query.add(new SMEquals("product_id", new SMString(jsonObj.getString("product_id"))));
List<SMObject> results = ds.readObjects("product", query);
SMObject product= results.get(0);
//product.getValue().get("categories"); how do i get this to be a String array?
At its simplest, that would look something like this:
List<SMValue> categories = (List<SMValue>)(rawObj.getValue().get("categories").getValue());
for (SMValue smString : categories) {
SMString stringValue = (SMString)smString.getValue();
//do whatever you want with the string value here
}
Obviously there are some unchecked casts in here, so you will want to add type/null checking to the appropriate sections depending on your data & schema.

Can Express with EJS render HTML to a variable (so I can send as e-mail)?

I am writing a nodejs application that will be sending html e-mail using emailjs. Basically I provide the html to send as a variable that I attach to the message.
Rather than build this variable using lots of string concatenation, I'd like to just render a view using express/ejs and save the contents to the variable.
So instead of doing:
messageHtml = '<html>'+ ....
message.attach({data: messageHtml, alternative: true});
I'd like to do something like:
messageHtml = render('emailTemplate.ejs', viewArgs);
message.attach({data: messageHtml, alternative: true});
Can this be done, and if so, how?!
Just require ejs directly and use as per the example, e.g simplified usage (without caching):
var ejs = require('ejs')
, fs = require('fs')
, str = fs.readFileSync(__dirname + '/emailTemplate.ejs', 'utf8');
var messageHtml = ejs.render(str, viewArgs);
message.attach({data: messageHtml, alternative: true});

Zend Framework export Doctrine query results to XML file

I have a need to export certain queries to xml files. I have this working in that the file is created and the data are exported, however I'm receiving the following error on screen as the file is being exported and not displayed.
This page contains the following errors:
error on line 3 at column 1: Extra content at the end of the document
I'll admit that I'm new to this as most of you are aware but is there a way I can export and just display a confirmation message to the user that the report has been saved, or am I going about this the wrong way completely?
My code is below
My controller
public function init()
{
// allow certain reports to be exported to xml
// initialize context switch helper
$contextSwitch = $this->_helper->getHelper('contextSwitch');
$contextSwitch->addActionContext('newsletterexport', 'xml')
->initContext();
}
public function newsletterexportAction()
{
$q = Doctrine_Query::create()
->select('c.firstname,c.lastname,c.address1,c.address2,c.address3,t.county')
->from('PetManager_Model_Clients c')
->leftJoin('c.PetManager_Model_Counties t')
->where('c.consentToNews=1');
$result = $q->fetchArray();
if (count($result) >= 1) {
$this -> view -> records = $result;
}
}
EDIT
Ok I tried moving the code from the xml.phtml into my controller as suggested and tried to save the document with save, but now I get the start of the xml document as shown below but no records are saved to the document.
<?xml version="1.0" encoding="utf-8"?>
<petmanager:document xmlns:petmanager="http://petmanager"><petmanager:records/></petmanager:document>
My controller code as of this edit
public function newsletterexportAction()
{
$q = Doctrine_Query::create()
->select('c.firstname,c.lastname,c.address1,c.address2,c.address3,t.county')
->from('PetManager_Model_Clients c')
->leftJoin('c.PetManager_Model_Counties t')
->where('c.consentToNews=1');
$result = $q->fetchArray();
if (count($result) >= 1) {
//$this -> view -> records = $result;
$docpref="newsletterexport";
$docDate=date('y-m-d');
$ext=".xml";
$docname=$docpref.$docDate.$ext;
// create XML document
$dom = new DOMDocument('1.0', 'utf-8');
// create root element
$root = $dom->createElementNS('http://petmanager','petmanager:document');
$dom->appendChild($root);
// convert to SimpleXML
$xml = simplexml_import_dom($dom);
// add resultset elements
$records = $xml->addChild('records');
foreach($this->$result as $r){
$record = $records->addChild('record');
$record->addChild('firstName',$this->escape($r['firstName']));
$record->addChild('lastName',$this->escape($r['lastName']));
$record->addChild('address1',$this->escape($r['address1']));
$record->addChild('address2',$this->escape($r['address2']));
$record->addChild('address3',$this->escape($r['address3']));
$record->addChild('county',$this->escape($r['PetManager_Model_Counties']['county']));
}//end of foreach
// saave document
$xml->saveXML();
$dom->save('D:/reports/exports/'.$docname.'');
}
DomDocument::saveXML() doesnt take a file path - it returns the XML document as text. If you want to save it directly as a file like youre doing you use DomDocument::save().
All that logic in your phtml should be in your controller. You have also set the context to xml, so the view is going to output XML to the browser, not HTML... so id doesnt make sense to display a confirmation message unless its encoded in XML, otherwise you need to use the default context (HTML). So if you want to save the file to the webserver and display a confirmation you would do:
public function exportXmlAction(){
// remove the context switch from init
// do your doctrine stuff
// build the xml DOM as $xml
$xml->save('path/to/file');
$this->message = 'File was exported successfully!';
}
// in your phtml
<?php echo $this->message; ?>
If you want to display the xml on screen:
public function exportXmlAction(){
// do your doctrine stuff
// build the xml DOM as $xml
$this->xmlDom = $xml;
}
// in your phtml
<?php echo $this->xmlDom->saveXml(); ?>
The question i have though is whay would a user want ot export xml to the server. When you call DomDocument::save() youre saving that file to a path on the server, not the user's machine so what would be the point of exporting the xml to the server where the user has no access to it?