Asked  7 Months ago    Answers:  5   Viewed   31 times

If you check it out I have a bit of a problem with the following, I have a form (webbooks.phtml) in which I use a jQuery function -webbooks.phtml ( is actually a menu and in fact a view where you type the product that you are searching for) -webbookscontroller ( this is a controller, which uses an API to get the data out of an SQL data base based on the string/number...etc given by the webbooks.phtml) -index.phtml (this is the view space where the result should be viewed.)

This is the array that I get:

{"book_title":"Bioethics in the 21st Century",

I can see this array when I


and I want this array to get to my view (index.phtml)? I am new to PHP and I'm trying to do something that may be bad practice and may well be impossible. I'm basically just hacking something together to test my knowledge and see what PHP can do. Is this possible?



This is an example of basic usage of calling Zend Controller with ajax/json and get response to the same phtml, so you can use it in your code.

In .phtml file I have javascript which call (in IndexController) the action ajaxAction():

<script language = "Javascript">
var param1 = 'first';  //or get value from some DOM element
var param2 = 'second'; //or get value from some DOM element

      url: '/default/index/ajax',
      type: 'POST',
      data: {param1: param1, param2:param2 },
      dataType: "json",
      success: function(result){
            var return1 = result.return1;
            var return2 = result.return2;
            // return1 and return2 is value from php file.
            // fill out DOM element or do the windows.location()

In IndexController the ajaxAction() should get request:

public function ajaxAction(){

    $param1 = $this->_request->getParam('param1');
    $param2 = $this->_request->getParam('param2');


    $results = array(
        'return1' => 'value1',
        'return2' => 'value2'


In any way I suggest to listen the @jakenoble and look at(learn) Context Switching in Zend.

Wednesday, March 31, 2021
answered 7 Months ago

As @Aydin Hassan commented, I've tried with:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$excelOutput = ob_get_clean();

And then simply passed $excelOutput to the response content, and it works simply great!

Saturday, May 29, 2021
answered 5 Months ago

In order to make your multipart/formdata work, you must add some extra stuff in your ajax-request:

cache: false,
contentType: false,
processData: false,

You can easily create your data-field by doing this:

var uploadData = $("#uploadFile").prop("files")[0];
var newData = new FormData();

$.each($('#uploadFile').prop("files"), function(i, file) {
    newData.append('file-'+i, file);

in your ajax-request you'll have to set this:

data: newData
Saturday, May 29, 2021
answered 5 Months ago

I believe that you are not building the request body correctly. First, you need to include part boundary (random text) in content type header. For example,

Content-Type: multipart/form-data; boundary=----WebKitFormBoundarySkAQdHysJKel8YBM

Now format of request body will be something like

Content-Disposition: form-data;name="key"

Content-Disposition: form-data;name="param2"

Content-Disposition: form-data;name="fileUpload"; filename="y1.jpg"
Content-Type: image/jpeg 

[image data goes here]

I will suggest you to use tool such as Fiddler to understand how these requests are built.

Thursday, June 24, 2021
answered 4 Months ago

Run phpunit with the -stderr flag, (newer versions may use --stderr instead) e.g.

 phpunit -stderr mytest.php
 # or
 phpunit --stderr mytest.php

This directs phpunit's output to stderr, preventing it from interrupting HTTP header generation.

It's possible that the test works on your friend's machine because he has output buffering enabled (although I'm not sure if that's relevant in a CLI context).

Wednesday, July 28, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :