Zend : Error Occurs when create html file from zend phtml file for multiple employee - zend-framework

//controller function
function sendBulkMailAction(){
$template = "estimated-festival-bill-single.phtml";
foreach ($employeeArr as $profile_id => $employeeValue) {
$someData = array(); //here include some salary data
$model = new ViewModel($someData);
$model->setTemplate($template);
$htmlContent = "<!DOCTYPE html>\n\r<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\r<head>
<meta charset=\"utf-8\">
</head>
<body>"
. $this->getServiceLocator()->get('viewrenderer')->render($model)
. "</body>
</html>";
//create html file
//create pdf link from html by wkhtmlToPdf
//send this link via email to employee
}
}
//estimated-festival-bill-single.phtml
//simple code
<div> Employee Name</div>
<br>
<div><?php echo _get_salary_html(); ?></div>
<?php
function _get_salary_html(){
return "Salary Data";
}
?>
error show
Fatal error: Cannot redeclare _get_salary_html() (previously declared in G:\xampp\htdocs\ums\module\Hrm\view\hrm\salary-reports\estimated-salary-bill-single.phtml:9) in G:\xampp\htdocs\ums\module\Hrm\view\hrm\salary-reports\estimated-salary-bill-single.phtml on line 10
hints: when single employee its ok but for multiple employee show error

Because you are re-declaring function unknowingly. Add a condition around the function like below.
if (!function_exists('_get_salary_html')) {
function _get_salary_html() {
........
}
}

Related

Missing argument 1 for Illuminate\Support\Manager::createDriver() while sending mail in laravel

my .env file is:
MAIL_DRIVER=mail
MAIL_HOST=smtp.mandrillapp.com
MAIL_PORT=587
MAIL_USERNAME=sabin.maharjan456#gmail.com
MAIL_PASSWORD=****************************
Mailer.php
<?php namespace App\Http\Controllers;
class Mailer{
public function sendTo($email, $subject, $view, $data = array())
{
\Mail::queue($view, $data, function($message) use($email, $subject)
{
$message->to($email)->subject($subject);
});
return "Mail has been sent";
}
public function welcome($formData)
{
$subject = "User Message was arrived !";
$data['name'] = $formData['name'];
$data['email'] = $formData['email'];
$data['mobile'] = $formData['mobile'];
$data['subject'] = $formData['subject'];
$data['bodymessage'] = $formData['message'];
$view = 'emails.welcome';
return $this->sendTo(['sabin.maharjan456#gmail.com'],$subject,$view,$data);
}
}
contoller:
public function postContactFormRequest(CreateContactFormRequest $request,Mailer $mailer)
{
$formData = $request->all();
$this->mailer->welcome($formData);
}
view file:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
</head>
<body>
<h2>User Message</h2>
<p><b>Email Address:</b> {{ $email }}</p>
<h4>User Name : {{ $name }}</h4>
<p> Phone Number :{{ $mobile}}</p>
<p>Message :{{ $bodymessage }} </p>
</body>
</html>
this is my file:
i get a continious error while trying to send email.
Missing argument 1 for Illuminate\Support\Manager::createDriver(), called in /home/robustit/public_html/nic-website/vendor/laravel/framework/src/Illuminate/Support/Manager.php on line 89 and defined
I have had issues with this until now.
What you want is to check your .env file and make sure your database parameters are right, but also you want these:
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
For some reason I got these to have empty fields. And then it worked for me!

How to process the JSON data using .getJSON

My business functionality is to format JSON code returned from database and then use AJAX to process the JSON content and need to use only ".getJSON" instead of ".ajax"
The point where i was struck up is: how to sent the parameters using .getJSON to another page (customer.php) as i need to search for the customer data from database and return result in JSON formate.[The "data" parameter which holds key&value pair that needs to be sent to the server.]
Code from ajaxcall.php(where .getJSON is used)
<head>
<script>
$(document).ready(function(){
function search(){
var x=$("#srh").val();
if(x!=""){
$.getJSON({
url:'/customer.php',
data:{value:"x"},
success:function (data)
{
content= data;
$("#result").html(content[0].cust_id);
}
});
}
}
$("#button").click(function(){
search();
});
});
</script>
</head>
<body>
<input type="text" id="srh" placeholder="Enter the Name of the Customer"/>
<input type="button" id="button" value="search" />
<div id="result"></div>
</body>
Here, i need to pass the X parameter to customer.php using getJSON.The way i am passing is not working!
Code from customer.php(where i need to get search term (X parameter as input) $var=$_POST["value"]
and fetch the data from database using X parameter in where condition and return data in JSON content)
<?php
$conn = new mysqli("localhost", "xyz", "12345", "cust");
$var=$_GET['value'];
if (mysqli_connect_errno())
{ echo 'connect not possible to database: ' . mysqli_connect_error($conn); }
else
{
$query="SELECT cust_fname,cust_lname,cust_id,cust_addresa,cust_phone
from customer where UPPER(cust_lname) like UPPER('%" . $x. "%') ";
$result = mysqli_query($conn, $query);
if (!$result) { die("Not Found ! " . mysqli_error($conn)); }
else
{
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$json = json_encode($rows);
}
mysqli_free_result($result);
mysqli_close($conn);
print $json;
}
} ?>
Appreciate your pointer on this! Thanks in Advance.

How to filter New WP Query by Custom Field Value?

I am creating new pages for each of my categories in wordpress. The post editor has a custom field that allows the selection of a sector type, this gets applied to the post on update. The custom field key is: sector, for custom field meta value options lets use SectorA, SectorB and SectorC. I am using a custom post type called projects.
I followed the advice at this link http://weblogtoolscollection.com/archives/2008/04/13/how-to-only-retrieve-posts-with-custom-fields/
How can I change the query line in the code below so that it filters the loop by a Sector name, lets use SectorA. I'll then reuse the code on each template page changing the value to SectorB and SectorC on the other pages.
I think this needs changing somehow:
$customPosts->query('showposts=5&sector=sectorA&post_type=projects' );
Currently it echos the sector value and description value successfully but is showing all the posts. So my attempt to limit it to sectorA using sector=sectorA doesn't seem to work?
This code is in functions.php:
function get_custom_field_posts_join($join) {
global $wpdb, $customFields;
return $join . " JOIN $wpdb->postmeta postmeta ON (postmeta.post_id = $wpdb->posts.ID and postmeta.meta_key in ($customFields)) ";
}
function get_custom_field_posts_group($group) {
global $wpdb;
$group .= " $wpdb->posts.ID ";
return $group;
}
And this code is on the Template Page:
<?php /* Begin Custom Field Posts */ ?>
<h2>Custom Posts</h2>
<ul>
<?php
global $customFields;
$customFields = "'sector', 'description'";
$customPosts = new WP_Query();
add_filter('posts_join', 'get_custom_field_posts_join');
add_filter('posts_groupby', 'get_custom_field_posts_group');
$customPosts->query('showposts=5&sector=sectorA&post_type=projects' );//Uses same parameters as query_posts
remove_filter('posts_join', 'get_custom_field_posts_join');
remove_filter('posts_groupby', 'get_custom_field_posts_group');
while ($customPosts->have_posts()) : $customPosts->the_post();
$sector = get_post_custom_values("sector");
$description= get_post_custom_values("description");?>
<li><?php echo $sector[0]; ?></li>
<li><?php echo $description[0]; ?></li><br />
<?php endwhile; ?>
</ul>
<?php /* End Custom Field Posts */ ?>
Thanks for your help
May be this what you want
function get_custom_field_posts_join($join) {
global $wpdb, $customSector;
return $join . " JOIN $wpdb->postmeta postmeta ON (postmeta.post_id = $wpdb->posts.ID and postmeta.meta_key = 'sector' and postmeta.value = '$customSector') ";
}
and modification of page
$customSector='sectorA';//<--- insert this
add_filter('posts_join', 'get_custom_field_posts_join');
Try using this code.
<?php
$sector = get_post_meta($post->ID, "sector", false);
if ($sector[0]=="") { ?>
<!-- If there are no custom fields, show nothing -->
<?php } else { ?>
<div class="sector">
<h3>Title</h3>
<?php foreach($sector as $sector) {
echo '<blockquote><p>'.$sector.'</p></blockquote>';
} ?>
</div>
<?php } ?>

How to use Zend ProgressBar in a Zend MVC application

I've been trying to use the JsPush Zend progress bar in a Zend MVC application, but have not been successful. I've used the JsPush.php example found on github to create a standalone progress bar test application, but this does not use the Zend MVC framework. When I apply the CSS, HTML, JavaScript, and PHP code from the JsPush example program, I see my progress bar appear (the CSS works) but I don't get any results during my socket write process. I've used the JsPush CSS code verbatim in a css file that is linked to my application so I won't repeat that here. Below are exerpts from my MVC application, the controller code:
protected function _sendFile($job)
{
$fp = fopen($job->source_file, "rb");
if($fp == null || $fileData['size'] == 0) {
$this->view->errorMessage = 'Error - file open failed for ' . $job->source_file;
return false;
}
$this->totalXmitSize = $fileSize;
$this->currentXmitSize = 0;
$progressMessage = '';
$adapter = new Zend_ProgressBar_Adapter_JsPush(array
('updateMethodName' => 'Zend_ProgressBar_Update',
'finishMethodName' => 'Zend_ProgressBar_Finish'));
$progressBar = new Zend_ProgressBar($adapter, 0, $this->totalXmitSize);
while(!feof($fp)) {
$blkSize = ($fileSize > 1024) ? 1024 : $fileSize;
$xmitBuf = fread($fp, $blkSize);
if($xmitBuf === false || !strlen($xmitBuf)) {
$this->view->errorMessage = 'Error - file open failed for ' . $job->source_file;
return false;
}
if($this->_writeData($xmitBuf, $blkSize) == false) {
return false;
}
$fileSize -= $blkSize;
$this->currentXmitSize += $blkSize;
$progress = $this->_calculateXmitProgress();
if($progress < 25) {
$progressMessage = 'Just beginning';
} elseif($progress < 50) {
$progressMessage = 'less than half done';
} elseif($progress < 75) {
$progressMessage = 'more than half done';
} else {
$progressMessage = 'almost done';
}
$progressBar->update($this->currentXmitSize, $progressMessage);
if($fileSize <= 0) {
break;
}
}
fclose($fp);
$xmitBuf = '';
$bufLen = 0;
if($this->_readData($xmitBuf, $bufLen) === false) {
return false;
}
$progressBar->finish();
if(strncmp($xmitBuf, MSG_STATUS_OK, strlen(MSG_STATUS_OK)) != 0) {
$this->view->errorMessage = 'Error - invalid response after file transfer complete';
return false;
}
return true;
}
The view code:
<?php
$this->title = "My Title";
$this->headTitle($this->title);
$this->layout()->bodyScripts = 'onload="startProgress();"';
?>
<p class="errors"> <?php echo $this->errorMessage ?> </p >
<?php echo $this->form->setAction($this->url());
?>
<div id="progressbar">
<div class="pg-progressbar">
<div class="pg-progress" id="pg-percent">
<div class="pg-progressstyle"></div>
<div class="pg-invertedtext" id="pg-text-1"></div>
</div>
<div class="pg-text" id="pg-text-2"></div>
</div>
</div>
<div id="progressBar"><div id="progressDone"></div></div>
The layout.phtml code:
function startProgress()
{
var iFrame = document.createElement('iframe');
document.getElementsByTagName('body')[0].appendChild(iFrame);
iFrame.src = 'MyController.php';
}
function Zend_ProgressBar_Update(data)
{
document.getElementById('pg-percent').style.width = data.percent + '%';
document.getElementById('pg-text-1').innerHTML = data.text;
document.getElementById('pg-text-2').innerHTML = data.text;
}
function Zend_ProgressBar_Finish()
{
document.getElementById('pg-percent').style.width = '100%';
document.getElementById('pg-text-1').innerHTML = 'done';
document.getElementById('pg-text-2').innerHTML = 'done';
}
</script>
</head>
<body <?php echo $this->layout()->bodyScripts ?>>
<div>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->layout()->content; ?>
</div>
When this runs I get a ton of JavaScript in the page source, but no progress results:
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":0,"max":3397,"percent":0,"timeTaken":0,"timeRemaining":null,"text":null});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":1024,"max":3397,"percent":30.14424492199,"timeTaken":0,"timeRemaining":0,"text":"less than half done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":2048,"max":3397,"percent":60.28848984398,"timeTaken":0,"timeRemaining":0,"text":"more than half done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":3072,"max":3397,"percent":90.43273476597,"timeTaken":0,"timeRemaining":0,"text":"almost done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":3397,"max":3397,"percent":100,"timeTaken":0,"timeRemaining":0,"text":"almost done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Finish();</script><br />
All of this JavaScript pushes my form out of view. I have spent days on the Zend documentation site and scouring the web to find examples of someone successfully using Zend ProgressBar in a MVC framework application, but can not find any working examples. Thanks in advance for any help.
Well I have been successful in getting a JsPush progress bar to work to some degree, but not 100% correct for my application.
The progressbar works, but the form results end up in the hidden iframe. There is no way to get to the submit buttons on that iframe, so my user has to use the back button to get out of the form.
The only way to get the progress bar to work is to use the target attribute in the form and assign it to the name attribute of the iframe. If I don't use the target attribute, the form scrolls for every call to progressBar->update;. So my form results end up on the parent page several hundred lines scrolled down and the scroll bar never works.
I've tried using the example from the Zend documentation, but it doesn't work. This is my first venture into the Zend framework and it has been very frustrating and disappointing. Not a single response to my original question from 28 days ago.
I had same problem. For me it worked since I did the following steps.
Go to the php.ini and check if the following Data is set in your php.ini.
output_buffering = Off
;output_handler =
zlib.output_compression = Off
;zlib.output_handler =
Then go to class Zend_ProgressBar_Adapter_JsPush and find the Method - which is at the bottom - _outputData. Delete everything in this Method and input
// 1024 padding is required for Safari, while 256 padding is required
// for Internet Explorer. The <br /> is required so Safari actually
// executes the <script />
echo str_pad($data . '', 1024, ' ', STR_PAD_RIGHT) . "\n";
echo(str_repeat(' ',256));
if (ob_get_length()){
#ob_flush();
#flush();
#ob_end_flush();
}
#ob_start();

Zend Form Element Row needs either an id or class set through Zend_Config_Ini

I have the following default decorators in a Zend_Config_Ini to set up my form:
elementDecorators.viewHelper.decorator = "ViewHelper"
elementDecorators.label.decorator = "Label"
elementDecorators.errors.decorator = "Errors"
elementDecorators.htmlTag.decorator = "HtmlTag"
elementDecorators.htmlTag.options.tag = "li"
I have the following element definition also in the Zend_Config_Ini:
elements.username.type = "text"
elements.username.options.label = "Username:"
elements.username.options.required = true
and the following output is produced:
<li>
<label for="username" class="required">Username:</label>
<input type="text" name="username" id="username" value="" />
</li>
Now what I need to know is, how do I (through the ini config file preferably), set the id or class of the LI tag? I would like the following output:
<li id="form-username-element"> ... </li>
or
<li class="form-2col"> ... </li>
Update:
I was able to get it by overriding all the decorators in the element config itself like this:
elements.username.options.decorators.viewHelper.decorator = "ViewHelper"
elements.username.options.decorators.label.decorator = "Label"
elements.username.options.decorators.errors.decorator = "Errors"
elements.username.options.decorators.htmlTag.decorator = "HtmlTag"
elements.username.options.decorators.htmlTag.options.tag = "li"
elements.username.options.decorators.htmlTag.options.class = "username-row-element"
So that will work, however creates a lot of duplication as that would have to go onto every element (with the single change of the last line which would be the class setting itself). So what I am NOW wondering, is, from the ini file, is there a way to just override the class name using the default decorators (rather than having to duplicate all of the decorators for each element)?
Easiest thing to do is create your own Decorator. For instance, I've created an ElementWrap decorator, which wraps each element with a div and adds the necessary class and id. It could look something like this:
class Form_Decorator_ElementWrap extends Zend_Form_Decorator_Abstract
{
public function render($content)
{
$element = $this->getElement();
if($this->getOption('openOnly')) {
return '<div class="'.$this->getClass().'" id="'.$this->getId().'">' . $content;
} else if($this->getOption('closeOnly')) {
return $content . PHP_EOL . '</div>' . PHP_EOL;
} else {
return '<div class="'.$this->getClass().'" id="'.$this->getId().'">' . $content . '</div>';
}
}
public function getClass()
{
$element = $this->getElement();
$classes = array(
'field_wrap',
'field_' . strtolower(substr(strrchr($element->getType(), '_'), 1)),
$this->getOption('class'),
);
if($element->hasErrors()) {
$classes[] = 'field_error';
}
if($elementClass = $element->getAttrib('class')) {
$classes[] = $elementClass;
}
return implode(' ', array_filter($classes));
}
public function getId()
{
return 'fieldwrap-' . $element->getId();
}
}