Having trouble processing XML with PHP SimpleXML - simplexml

http://pastie.org/1701923 Here is the XML being returned from an API I am querying for zip codes.
I want to pull the data out of each entry and either loop it directly or put it into an array that I can loop. I can't seem to get it right. Here is the latest code I was using:
$xml = new SimpleXMLElement($results);
foreach($xml->zipcoderadius->zipcodes as $loc) {
$codes[] = (string)$loc['zipcode'];
}
print_r($codes);
die();
($results is the returned XML from CURL)
What is being output is Array ( [0] => [1] => [2] => [3] => [4] => )

I think this was,n be a string (zipcode). Try without string

I am not sure you're addressing the zip code correctly. For me the following works, assuming you stored your cURL result in $xmlStr previously.
$push = array();
$foo = simplexml_load_string($xmlStr);
foreach($foo->zipcoderadius->zipcodes->id as $bar) {
array_push($push, (string)$bar);
}
print_r($push);
Leading to the following output:
Array
(
[0] => 75969
[1] => 75970
[2] => 75971
)
By the way: the SimpleXML object looks like this:
object(SimpleXMLElement)#1 (1) {
["zipcoderadius"]=>
object(SimpleXMLElement)#4 (1) {
["zipcodes"]=>
object(SimpleXMLElement)#3 (32) {
["id"]=>
array(3) {
[0]=>
string(5) "75969"
[1]=>
string(5) "75970"
[2]=>
string(5) "75971"
}
["zipcode"]=>
array(3) {
[0]=>
string(5) "94945"
[1]=>
string(5) "94945"
[2]=>
string(5) "94945"
}
...

Related

Post Method with Guzzle doesn't work / Laravel 5

I want to execute a scheduled task with laravel, which make a post with a single param.
I already checked with Postman my POST, so, I just have to hit myurl.com with param ID=188888 for instance. I get it working with postman.
So, first, I'm making the Laravel command : check:time, which just performs the post, and then, once I get it working, I will schedule it.
Thing is it appears commands is doing nothing, and I have no error logs.
So, really, it is not so easy to debug it...
Here is my Command Code:
class CheckTime extends Command
{
protected $signature = 'check:time {empId}';
protected $description = 'Check your time';
public function handle()
{
$client = new Client;
$numEmp = $this->argument('empId');
$response = $client->post('http://example.com/endpoint.php', ['ID' => $numEmp]);
var_dump($response);
}
}
When I print $response, I get:
class GuzzleHttp\Psr7\Response#495 (6) {
private $reasonPhrase =>
string(2) "OK"
private $statusCode =>
int(200)
private $headers =>
array(6) {
'date' =>
array(1) {
[0] =>
string(29) "Wed, 01 Jun 2016 00:17:52 GMT"
}
'server' =>
array(1) {
[0] =>
string(22) "Apache/2.2.3 (Red Hat)"
}
'x-powered-by' =>
array(1) {
[0] =>
string(10) "PHP/5.3.15"
}
'content-length' =>
array(1) {
[0] =>
string(3) "146"
}
'connection' =>
array(1) {
[0] =>
string(5) "close"
}
'content-type' =>
array(1) {
[0] =>
string(24) "text/html; charset=UTF-8"
}
}
private $headerLines =>
array(6) {
'Date' =>
array(1) {
[0] =>
string(29) "Wed, 01 Jun 2016 00:17:52 GMT"
}
'Server' =>
array(1) {
[0] =>
string(22) "Apache/2.2.3 (Red Hat)"
}
'X-Powered-By' =>
array(1) {
[0] =>
string(10) "PHP/5.3.15"
}
'Content-Length' =>
array(1) {
[0] =>
string(3) "146"
}
'Connection' =>
array(1) {
[0] =>
string(5) "close"
}
'Content-Type' =>
array(1) {
[0] =>
string(24) "text/html; charset=UTF-8"
}
}
private $protocol =>
string(3) "1.1"
private $stream =>
class GuzzleHttp\Psr7\Stream#493 (7) {
private $stream =>
resource(311) of type (stream)
private $size =>
NULL
private $seekable =>
bool(true)
private $readable =>
bool(true)
private $writable =>
bool(true)
private $uri =>
string(10) "php://temp"
private $customMetadata =>
array(0) {
}
}
}
I checked that $numEmp is OK, also, I printed $response and everything seems to be fine
As I said, I also execute the post with Postman, and it works, so, I don't really understand what's going on...
Any idea??
As #Denis Mysenko wisely advised, I tried:
$response->getBody()->getContents()
and found out that my post was getting a SQL error message.
Solution: to pass form parameters with guzzle, you have to pass it like that:
response = $client->post('http://example.com/endpoint.php', [
'form_params' => [
'ID' => $empId,
...
]
]);

Import validated tab delimited file to MySQL with Laravel

Im trying to upload a tab delimited text file.
The issue could be that the columns is not always in the same order.
Once uploaded id like to do the following steps:
Validate column names. If validation passes -> 2
Read line by line in the file (preferably skip column names) and validate some of the values. If a line passes validation -> 3.
Create a model object and store it in an array for later bulk insertion.
Repeat for all lines in the file.
When all lines are done and everything is validated, bulk insert all the objects.
So far i have done the upload part and tried out some different solutions. But I'm pretty much stuck right now.
I'll paste my code from the controller (keep in mind that there is 40 columns in the file i have just written some of them):
public function store()
{
$file = Input::file('file');
$rules = array(
'file' => 'required|mimes:txt'
);
$validator = Validator::make(array('file'=> $file), $rules);
if($validator->passes()){
foreach(file($file) as $row) {
$row = explode("\t", $row);
$validator = Validator::make(array(
'X'=> $row[0],
'Y'=> $row[1],
'year'=> $row[2],
'provnr'=> $row[3],
'id'=> $row[4]
), Sample::$insertRules);
if($validator->passes()){
$sample = New Sample;
$sample->X = $row[0];
$sample->Y = $row[1];
$sample->year = $row[2];
$sample->provnr = $row[3];
$sample->costumer_id = $row[4];
$sample->save();
} else {
Session::flash('notice', 'Something is wrong!');
Session::flash('sample', $row[3]);
return Redirect::to('import');
}
}
exit;
Session::flash('success', 'Upload successfully');
return Redirect::to('import');
}
else {
// redirect back with errors.
return Redirect::to('import')->withInput()->withErrors($validator);
}
}
This works fine (no bulk insertion yet, ill tend to that later), but i'm not really fond of it, i think theres a better solution.
Don't mind the validation, it's not really finished yet.
What i end up with, if i print_r all the rows you can find below this text.
Right now its kind of hard since the column names is the first array. Somewhere along the line id like to remove it. Since it won't pass the other rows validation.
Array ( [0] => x [1] => y [2] => År [3] => Provnr )
Array ( [0] => 1315903.24 [1] => 6213877.72 [2] => 2014 [3] => 223 )
Array ( [0] => 1315819.62 [1] => 6213937.42 [2] => 2014 [3] => 224 )
So, i'm interested in you guys thoughts about this. Have you got any ideas?
I think it would be better to in some way convert the array, to objects. So i get something like a database result. I just don't know how.
I would like to be able to write $row['X'] in my foreach loop. I think that would be much better.
Is there some kind of way to make that possible? The column names would be each objects identification.
Im really thankful for you're help!
Edit:
So now the issue lies in the special characters of my file.
I have made some edits according to Bogdans comments.
I have included the full $columnMap
The code now looks like this:
$file = Input::file('file');
$rules = array(
'file' => 'required|mimes:txt'
);
$validator = Validator::make(array('file'=> $file), $rules);
if($validator->passes()){
$columns = [];
$columnMap = [
'x' => 'X',
'y' => 'Y',
'Ar' => 'Year',
'Provnr' => 'Provnr',
'Markning' => 'costumer_id',
'pH' => 'pH',
'P_AL' => 'P_AL',
'P_HCl' => 'P_HCl',
'K_AL' => 'K_AL',
'K_HCl' => 'K_HCl',
'Mg_AL' => 'Mg_AL',
'Cu_HCl' => 'Cu_HCl',
'K_Mg_kvot' => 'K_Mg_kvot',
'Bor' => 'Bor',
'Ca_AL' => 'Ca_AL',
'fe' => 'fe',
'al' => 'al',
'Mullhalt' => 'Mullhalt',
'Total_lerhalt' => 'Total_lerhalt',
'Sand_grovmo' => 'Sand_grovmo',
'Volymvikt' => 'Volymvikt',
'T_varde' => 'T_värde',
'S_varde' => 'S_värde',
'Basmattnadsgrad' => 'Basmättnadsgrad',
'Cd_HNO3' => 'Cd_HNO3',
'Kalkbehov' => 'Kalkbehov',
'Jordart' => 'Jordart',
'Fin_lerhalt' => 'Fin_lerhalt',
'Zn' => 'Zn',
'Cu' => 'Cu',
'Cr' => 'Cr',
'Ni' => 'Ni',
'Pb' => 'Pb',
'Hg' => 'Hg',
'Mineralkvave_Kg_N_ha' => 'Mineralkväve_Kg_N_ha',
'Mineralkvave_NO3_N' => 'Mineralkväve_NO3_N',
'Mineralkvave_NH4_N' => 'Mineralkväve_NH4_N',
'Mineralkvave_djup' => 'Mineralkväve_djup',
'Cystnematoder_potatis' => 'Cystnematoder_potatis',
'Cystnematoder_betor' => 'Cystnematoder_betor',
'Cystnematoder_spannmal' => 'Cystnematoder_spannmål',
'Ovrigt' => 'Övrigt'
];
foreach(file($file) as $i => $row)
{
$row = explode("\t", $row);
if($i == 0)
{
$columns = $row;
array_walk($columns, function (&$item)
{
$item = str_replace(
['ä', 'å', 'ö', 'Ä', 'Å', 'Ö'],
['a', 'a', 'o', 'A', 'A', 'O'],
utf8_encode($item)
);
});
continue;
}
$_row = array();
array_walk($row, function ($value, $index) use (&$_row, $columns, $columnMap)
{
$_row[$columnMap[$columns[$index]]] = $value; //*The issue is here.*
});
$row = $_row;
$validator = Validator::make($row, Sample::$insertRules);
if($validator->passes()){
$sample = New Sample;
foreach ($row as $property => $value)
$sample->{$property} = $value;
$sample->save();
} else
{
Session::flash('notice', 'Something is wrong!');
return Redirect::to('import');
}
}
I had to utf8_encode the header of the file, otherwise it wouldn't work. Could this be some issue with the text file?
It seems to be working until it is time to do array_walk on the row with values.
I then get this error: Undefined index: Ovrigt
If I var_dump $columns it looks like this:
array(42) { [0]=> string(1) "x" [1]=> string(1) "y" [2]=> string(2) "Ar" [3]=> string(6) "Provnr" [4]=> string(8) "Markning" [5]=> string(2) "pH" [6]=> string(4) "P_AL" [7]=> string(5) "P_HCl" [8]=> string(4) "K_AL" [9]=> string(5) "K_HCl" [10]=> string(5) "Mg_AL" [11]=> string(6) "Cu_HCl" [12]=> string(9) "K_Mg_kvot" [13]=> string(3) "Bor" [14]=> string(5) "Ca_AL" [15]=> string(2) "fe" [16]=> string(2) "al" [17]=> string(8) "Mullhalt" [18]=> string(13) "Total_lerhalt" [19]=> string(11) "Sand_grovmo" [20]=> string(9) "Volymvikt" [21]=> string(7) "T_varde" [22]=> string(7) "S_varde" [23]=> string(15) "Basmattnadsgrad" [24]=> string(7) "Cd_HNO3" [25]=> string(9) "Kalkbehov" [26]=> string(7) "Jordart" [27]=> string(11) "Fin_lerhalt" [28]=> string(2) "Zn" [29]=> string(2) "Cu" [30]=> string(2) "Cr" [31]=> string(2) "Ni" [32]=> string(2) "Pb" [33]=> string(2) "Hg" [34]=> string(20) "Mineralkvave_Kg_N_ha" [35]=> string(18) "Mineralkvave_NO3_N" [36]=> string(18) "Mineralkvave_NH4_N" [37]=> string(17) "Mineralkvave_djup" [38]=> string(21) "Cystnematoder_potatis" [39]=> string(19) "Cystnematoder_betor" [40]=> string(22) "Cystnematoder_spannmal" [41]=> string(8) "Ovrigt " }
If var_dump $columnMap it looks like this:
array(42) { ["x"]=> string(1) "X" ["y"]=> string(1) "Y" ["Ar"]=> string(4) "Year" ["Provnr"]=> string(6) "Provnr" ["Markning"]=> string(11) "costumer_id" ["pH"]=> string(2) "pH" ["P_AL"]=> string(4) "P_AL" ["P_HCl"]=> string(5) "P_HCl" ["K_AL"]=> string(4) "K_AL" ["K_HCl"]=> string(5) "K_HCl" ["Mg_AL"]=> string(5) "Mg_AL" ["Cu_HCl"]=> string(6) "Cu_HCl" ["K_Mg_kvot"]=> string(9) "K_Mg_kvot" ["Bor"]=> string(3) "Bor" ["Ca_AL"]=> string(5) "Ca_AL" ["fe"]=> string(2) "fe" ["al"]=> string(2) "al" ["Mullhalt"]=> string(8) "Mullhalt" ["Total_lerhalt"]=> string(13) "Total_lerhalt" ["Sand_grovmo"]=> string(11) "Sand_grovmo" ["Volymvikt"]=> string(9) "Volymvikt" ["T_varde"]=> string(8) "T_värde" ["S_varde"]=> string(8) "S_värde" ["Basmattnadsgrad"]=> string(16) "Basmättnadsgrad" ["Cd_HNO3"]=> string(7) "Cd_HNO3" ["Kalkbehov"]=> string(9) "Kalkbehov" ["Jordart"]=> string(7) "Jordart" ["Fin_lerhalt"]=> string(11) "Fin_lerhalt" ["Zn"]=> string(2) "Zn" ["Cu"]=> string(2) "Cu" ["Cr"]=> string(2) "Cr" ["Ni"]=> string(2) "Ni" ["Pb"]=> string(2) "Pb" ["Hg"]=> string(2) "Hg" ["Mineralkvave_Kg_N_ha"]=> string(21) "Mineralkväve_Kg_N_ha" ["Mineralkvave_NO3_N"]=> string(19) "Mineralkväve_NO3_N" ["Mineralkvave_NH4_N"]=> string(19) "Mineralkväve_NH4_N" ["Mineralkvave_djup"]=> string(18) "Mineralkväve_djup" ["Cystnematoder_potatis"]=> string(21) "Cystnematoder_potatis" ["Cystnematoder_betor"]=> string(19) "Cystnematoder_betor" ["Cystnematoder_spannmal"]=> string(23) "Cystnematoder_spannmål" ["Ovrigt"]=> string(7) "Övrigt" }
If i var_dump the first $row with values it looks like this:
array(42) { [0]=> string(10) "1315903.24" [1]=> string(10) "6213877.72" [2]=> string(4) "2014" [3]=> string(3) "223" [4]=> string(4) "6510" [5]=> string(3) "6.8" [6]=> string(4) "10.0" [7]=> string(0) "" [8]=> string(3) "9.5" [9]=> string(0) "" [10]=> string(4) "12.0" [11]=> string(0) "" [12]=> string(3) "0.8" [13]=> string(0) "" [14]=> string(5) "150.0" [15]=> string(0) "" [16]=> string(0) "" [17]=> string(0) "" [18]=> string(0) "" [19]=> string(0) "" [20]=> string(0) "" [21]=> string(0) "" [22]=> string(0) "" [23]=> string(0) "" [24]=> string(0) "" [25]=> string(0) "" [26]=> string(0) "" [27]=> string(0) "" [28]=> string(0) "" [29]=> string(0) "" [30]=> string(0) "" [31]=> string(0) "" [32]=> string(0) "" [33]=> string(0) "" [34]=> string(0) "" [35]=> string(0) "" [36]=> string(0) "" [37]=> string(0) "" [38]=> string(0) "" [39]=> string(0) "" [40]=> string(0) "" [41]=> string(12) "J038790-14 " }
Right now i have no idea what could be the issue. Is there something else i can post so you guys get a better understanding?
Since "Ovrigt" is last, it seems to work fine up until that one.
A wierd thing is that there seems to be a blank space in "Ovrigt " when i var_dump $columns.. Could that be it?
Assuming the first line of the file always contains the columns names, here's a quick approach to accomplish that:
// Define the array that will contain the columns names
$columns = [];
foreach($rows as $i => $row)
{
$row = explode("\t", $row);
// For the first row get the get the column names
if ($i == 0)
{
$columns = $row;
continue; // Skip this iteration
}
// Map each column name to every item in the row
$_row = array();
array_walk($row, function ($value, $index) use (&$_row, $columns)
{
$_row[$columns[$index]] = $value;
});
$row = $_row;
// You can now access row items with
// $row['X'], $row['Y'], etc.
...
}
If you know exactly that all columns will be present in the file (regardless of order), you can go a step further and map the column name from the file to the coresponding model property name. This will make it even more seamless to validate and populate each model:
// Define the array that will contain the columns names
$columns = [];
// Define the column mapping
// 'column name' => 'model property name'
$columnMap = [
'X' => 'X',
'Y' => 'Y',
'Ar' => 'year',
'Provnr' => 'provnr',
'id' => 'customer_id'
];
foreach($rows as $i => $row)
{
// Assuming the column names are always on the first row
if ($i == 0)
{
$columns = $row;
// Replace Swedish special chars with simple Latin chars
array_walk($columns, function (&$item)
{
$item = str_replace(
['ä', 'å', 'ö', 'Ä', 'Å', 'Ö'],
['a', 'a', 'o', 'A', 'A', 'O'],
trim($item)
);
});
continue; // Skip this iteration
}
// Map each column name to every item in the row
$_row = array();
array_walk($row, function ($value, $index) use (&$_row, $columns, $columnMap)
{
$_row[$columnMap[$columns[$index]]] = $value;
});
$row = $_row;
// Pass the $row directly to the validator because the mapped keys will work
$validator = Validator::make($row, Sample::$insertRules);
if($validator->passes()){
$sample = New Sample;
// You can iterate over the row and assign each value automatically
// because each item key is mapped to a property name
foreach ($row as $property => $value)
$sample->{$property} = $value;
$sample->save();
}
else
{
Session::flash('notice', 'Something is wrong!');
Session::flash('sample', $row[3]);
return Redirect::to('import');
}
}

Laravel error: 'preg_replace(): Parameter mismatch' on multiple file upload insert

I've got a form which allows for multiple entries into a database. Each of these rows contains a file upload field.
The fields are created as follows:
{{ Form::select('revision[]', ['0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6'], '0', ['class' => 'form-control artwork-revision']); }}
{{ Form::text('product[]', false, ['class' => 'form-control artwork-product', 'placeholder' => 'Please enter the product name']) }}
{{ Form::file('file[]', ['class' => 'artwork-file']) }}
My controller has a foreach loop to enter each row into the database but when I run it, I get the following error message: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array
The code works when it's adapted for a single file upload (i.e. without the foreach loop and with only one row to be inserted, fields created without the square brackets)
How can I get past this error and enter the info into the database?
Here is the foreach loop in my controller and a var_dump of the object.
Controller foreach loop:
$files = Input::file('file');
foreach($files as $file) {
// it's a new artwork row
$artwork = new Artwork;
// get the vars
$artwork->job_id = Input::get('job_id');
$artwork->revision = Input::get('revision');
$artwork->product = Input::get('product');
// it's pending
$artwork->status = 'P';
// sort the filename...
$filename = $file->getClientOriginalName();
$file = $file->move(base_path() . '/public/artwork/' . Input::get('job_id'), $filename);
// ...and put it in the $artwork object
$artwork->filename = 'artwork/' . $artwork->job_id . '/' . $filename;
// save it
$artwork->save();
}
var_dump($artwork) output - note that only one image filename is showing in this rather than two:
object(Artwork)#243 (21) {
["dates":protected]=>
array(1) {
[0]=>
string(10) "deleted_at"
}
["fillable":protected]=>
array(6) {
[0]=>
string(6) "job_id"
[1]=>
string(8) "filename"
[2]=>
string(6) "status"
[3]=>
string(8) "revision"
[4]=>
string(7) "product"
[5]=>
string(6) "reason"
}
["table":protected]=>
string(8) "artworks"
["connection":protected]=>
NULL
["primaryKey":protected]=>
string(2) "id"
["perPage":protected]=>
int(15)
["incrementing"]=>
bool(true)
["timestamps"]=>
bool(true)
["attributes":protected]=>
array(5) {
["job_id"]=>
string(1) "5"
["revision"]=>
array(2) {
[0]=>
string(1) "0"
[1]=>
string(1) "0"
}
["product"]=>
array(2) {
[0]=>
string(15) "Twist USB Drive"
[1]=>
string(19) "Eco Twist USB Drive"
}
["status"]=>
string(1) "P"
["filename"]=>
string(24) "artwork/5/12345-test.jpg"
}
["original":protected]=>
array(0) {
}
["relations":protected]=>
array(0) {
}
["hidden":protected]=>
array(0) {
}
["visible":protected]=>
array(0) {
}
["appends":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["touches":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["with":protected]=>
array(0) {
}
["morphClass":protected]=>
NULL
["exists"]=>
bool(false)
["forceDeleting":protected]=>
bool(false)
}
This is my new 'store' controller that solves the issue:
$artwork = new Artwork;
// standard bits
$artwork->job_id = Input::get('job_id');
$artwork->status = 'P';
// variables
$artwork->revision = Input::get('revision');
$artwork->product = Input::get('product');
$artwork->file = Input::file('file');
// count how many pieces of artwork are being uploaded (this could be any field)
$count = count($artwork->revision);
/* multi-file upload */
$i = 0;
// process each piece
foreach($artwork as $a) {
while($count > $i) {
// it's a new piece of artwork
$a = new Artwork;
// standard bits to object
$a->job_id = $artwork->job_id;
$a->status = $artwork->status;
// revision and product name to object
$a->revision = $artwork->revision[$i];
$a->product = $artwork->product[$i];
// get the file and move it
$file = $artwork->file[$i];
$filename = $file->getClientOriginalName();
$movefile = $file->move(base_path() . '/public/artwork/' . $artwork->job_id, $filename);
// filename to object
$a->filename = $filename;
// save the object to db
$a->save();
// add 1 to the count
$i++;
}
}
return Redirect::route('jobs.index');
I think you can't even select multiple files. Replace your file field with this one it has multiple attribute set to true which will allow multiple files to be selected at once and returns an array of files.
{{ Form::file('file[]', ['class' => 'artwork-file','multiple' => true]) }}

Laravel Flash Message with Redirect Not Working

In a Laravel 4 project I am trying to set a flash message after the user's record is saved.
In my controller, I have:
return Redirect::to("/manage/users/$id")->with('success', 'Updated!');
Upon the redirect, if I dump Session::all() I get:
array(1) { ["_token"]=> string(40) "zXuGrG6OhA3bbPy5gzfYPzTm7LOFqX8vB1qxf9Sq" }
If I dump $_SESSION directly, I get:
array(3) [
'_sf2_attributes' => array(1) [
'_token' => string (40) "rQPKVHizgvCJLUxMS3JPvbpI2A1ZZUpV1mNFHX5O"
]
'_sf2_flashes' => array()
'_sf2_meta' => array(3) [
'u' => integer 1404929806
'c' => integer 1404929806
'l' => string (4) "7200"
]
]
Does anyone know what may cause this or what I may be doing wrong?

Zend Log - Bad Log Priority

When I try to add a registerErrorHandler() to my log config in my bootstrap it gives the following error:
<b>Fatal error</b>: Uncaught exception 'Zend_Log_Exception' with message 'Bad log priority' in /public/fb/library/Zend/Log.php:280
Stack trace:
#0 /public/fb/application/Bootstrap.php(24): Zend_Log->__call('registerErrorHa...', Array)
#1 /public/fb/application/Bootstrap.php(24): Zend_Log->registerErrorHandler()
#2 /public/fb/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initLogging()
#3 /public/fb/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('logging')
#4 /public/fb/library/Zend/Application/Bootstrap/BootstrapAbstract.php(583): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL)
#5 /public/fb/library/Zend/Application.php(355): Z in
<b>/public/fb/library/Zend/Log.php</b> on line <b>280</b>
Bootstrap.php
protected function _initLogging(){
$log = new Zend_Log();
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH .'/../data/logs/app.log');
$log->addWriter($writer);
$log->registerErrorHandler();
}
Output Zend_Debug::dump($log):
object(Zend_Log)#20 (6) {
["_priorities":protected] => array(8) {
[0] => string(5) "EMERG"
[1] => string(5) "ALERT"
[2] => string(4) "CRIT"
[3] => string(3) "ERR"
[4] => string(4) "WARN"
[5] => string(6) "NOTICE"
[6] => string(4) "INFO"
[7] => string(5) "DEBUG"
}
["_writers":protected] => array(1) {
[0] => object(Zend_Log_Writer_Stream)#21 (3) {
["_stream":protected] => resource(59) of type (stream)
["_filters":protected] => array(0) {
}
["_formatter":protected] => object(Zend_Log_Formatter_Simple)#22 (1) {
["_format":protected] => string(51) "%timestamp% %priorityName% (%priority%): %message%"
}}}
["_filters":protected] => array(0) {
}
["_extras":protected] => array(0) {
}
["_defaultWriterNamespace":protected] => string(15) "Zend_Log_Writer"
["_defaultFilterNamespace":protected] => string(15) "Zend_Log_Filter"
}
Thx for helping.
The error is thrown in Zend_Log::__call() magic method. since __call() is being used, this means that the referenced method does not exist in the object explicitly, so PHP has called the object's __call() magic method.
Are you sure there is no typo in the name of the method right where you are calling it?
Are you sure the version of ZF you are using actually supports this method? I checked my ZF installation (1.11.4) and on line 280 of Zend/Log.php file there is something else not related to this issue.
Updating your ZF installation to the last version could be helpful.

Resources