Magento 1.7 Cannot send headers; headers already sent in - php

SOLVED
I solved this issue with Jonathan Hussey help
I changed this line:
$mModel->getCollection()->load($mId)->getData();
for this:
$mModel->getCollection()->addFieldToFilter('met_id',$Id)->getSelect();
Problem
I created custom module which added tab to admin product page with additional text field.
When I try save this product I get this error:
a:5:{i:0;s:140:"Cannot send headers; headers already sent in /home/nano/domains/mydomain/public_html/gw/lib/Varien/Data/Collection/Db.php, line 693";i:1;s:1630:"#0 /home/nano/domains/mydomain/public_html/gw/lib/Zend/Controller/Response/Abstract.php(148): Zend_Controller_Response_Abstract->canSendHeaders(true)...
I saw that this error created in Observer.php:
$mId = $collection['m_id'];
$mModel->getCollection()->load($mId)->getData(); <-- this line give an error
$data['met_id'] = $mId;
$data['product_id'] = $product->getId();
$data['metf1'] = $this->_getRequest()->getPost('f1');
$mModel->setData($data);
$mModel->save();
Do you have any ideas how fix this ?
EDIT
content of admin template tab file:
<?php
$product = Mage::registry('current_product');
$mItem = Mage::getModel('mmodel/mmodel')->getCollection()->
addFilter('product_id',$product->getId())->getFirstItem();
echo '<div class="input-field">
<label for="f1">File</label>
<input type="text" class="input-text" name="f1" id="f1" value='.$mItem['f1'].' />
</div>';
Debug backtrace after line $mModel->getCollection()->load($mId)->getData(); from Observer.php
SELECT `main_table`.* FROM `mmodel` AS `main_table`
Debug Backtrace:
File Line Function
/home/nano/domains/mydomain/public_html/gw/app/code/local/GW/MModel/Model/Observer.php 42 printDebugBacktrace
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php 1338 saveProductTabData
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php 1317 _callObserverMethod
/home/nano/domains/mydomain/public_html/gw/app/Mage.php 468 dispatchEvent
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/Abstract.php 466 dispatchEvent
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Catalog/Model/Product.php 548 _afterSave
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/Abstract.php 319 _afterSave
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php 714 save
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Action.php 419 saveAction
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php 250 dispatch
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Front.php 176 match
/home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php 354 dispatch
/home/nano/domains/mydomain/public_html/gw/app/Mage.php 704 run
/home/nano/domains/mydomain/public_html/gw/index.php 87 run

When working with collections you should only pass arguments to ->load() if you want the SQL for that collection to be logged or output. If you don't want the collection to return all items you can pull the select object from the collection with ->getSelect() and filter with standard Zend methods this way.
If you trace back your collection command you will see because you pass an argument it echo's out the collection SQL.
$mModel->getCollection()->load($mId)->getData();
Have a look at lib/Varien/Data/Collection/Db.php as per the error message and find the load() method. You will see that it accepts two aguments, $printQuery and $logQuery, you have passed an argument to $printQuery. A few lines down in the method you see:
$this->printLogQuery($printQuery, $logQuery);
Looking at the printLogQuery() method you will see that anything passed as the $printQuery argument which evaluates to true triggers the echo on line 693 as per the error message:
echo is_null($sql) ? $this->getSelect()->__toString() : $sql;
This is what is sending headers in your case. Remove the argument from ->load() or pass false and it should fix your problem.

Related

Fatal error: Uncaught Error: Call to undefined function mysql_pconnect() when using phpGACL

Using phpGACL with db_type = "mysqli" in gacl.ini.php still got below error,
"Fatal error: Uncaught Error: Call to undefined function
mysql_pconnect()"
when create gacl class but phpGACL admin works fine.
<?php
include ("gacl.class.php");
$gacl = new gacl();
?>
I expect it should work fine as phpGACL admin do.
Finally, I make a small patch to make it work.
Change the code in gacl.class.php line 110.
function gacl($options = NULL) {
to
function __construct($options = NULL)
When create a gacl object, it must passing the db_type parameter instead of rely on gacl.ini.php setting.
$gacl = new gacl(array("db_type"=>"mysqli"));
Modify gacl.class.php line 455, remove & sign
$row =& $rs->FetchRow();
to
$row = $rs->FetchRow();
Modify profiler.inc line 37, 180
function Profiler( $output_enabled=false, $trace_enabled=false);
$tmp=split(" ",microtime());
to
function __construct( $output_enabled=false, $trace_enabled=false)
$tmp=explode(" ",microtime());
In order to make build in GACL admin work perfectly, also need to update ADODB, Smarty2 to latest version 2.6.31 (Smarty 3 is not compatible). acl_debug.tpl line 42 add # sign to count function.
{if #count($acls) gt 0}
# sign to by pass count uncountable error as a quick fix. Need further study the code for long term solution.
Fix a bug in group_admin.php
$formatted_groups = $gacl_api->format_groups($gacl_api->sort_groups($group_type), HTML);
to
$formatted_groups = $gacl_api->format_groups($gacl_api->sort_groups($group_type), 'HTML');

The $MetaTags(false) variable breaks the page (SilverStripe 3.7.1)

(First of all I'm still trying to figure my way around in SilverStripe so please be gentle)
I'm having a problem with one of the pages on a site where the error is:
[User Error] Uncaught Error: Call to a member function RelativeLink() on null
This is happening in Line 522 in SiteTree.php which has not been altered in any way.
516 if($this->ParentID && self::config()->nested_urls) {
517 $parent = $this->Parent();
518 // If page is removed select parent from version history (for archive page view)
519 if((!$parent || !$parent->exists()) && $this->IsDeletedFromStage) {
520 $parent = Versioned::get_latest_version('SiteTree', $this->ParentID);
521 }
522 $base = $parent->RelativeLink($this->URLSegment);
523 } elseif(!$action && $this->URLSegment == RootURLController::get_homepage_link()) {
524 // Unset base for root-level homepages.
525 // Note: Homepages with action parameters (or $action === true)
526 // need to retain their URLSegment.
527 $base = null;
528 }
After looking at the stack-trace I figured I would look in the Head.ss file and tried to comment out things in order to narrow down my search. So I found out that if I remove the $MetaTags(false) variable in Head.ss everything is working fine.
Trace:
SiteTree->RelativeLink()
SiteTree.php:468
SiteTree->Link()
SiteTree.php:484
SiteTree->AbsoluteLink()
Translatable.php:1583
Translatable->MetaTags(http://silverstripe.org" /> ,,,,,,)
Object.php:1068
SS_Object->extend(MetaTags,http://silverstripe.org" /> )
SiteTree.php:1429
SiteTree->MetaTags(false)
Object.php:746
SS_Object->__call(metatags,Array)
ViewableData.php:466
ViewableData->obj(MetaTags,Array,,1)
ViewableData.php:539
ViewableData->XML_val(MetaTags,Array,1)
SSViewer.php:187
SSViewer_Scope->__call(XML_val,Array)
SSViewer.php:650
SSViewer_DataPresenter->__call(XML_val,Array)
.cache.themes.express.templates.Includes.Head.ss:23
include(/var/www/jackon.no/silverstripe-cache/www-data-php7.0.30-0ubuntu0.16.04.1/.cache.themes.express.templates.Includes.Head.ss)
SSViewer.php:1172
SSViewer->includeGeneratedTemplate(/var/www/jackon.no/silverstripe-cache/www-data-php7.0.30-0ubuntu0.16.04.1/.cache.themes.express.templates.Includes.Head.ss,Product_Controller,Array,Array,SSViewer_DataPresenter)
SSViewer.php:1234
SSViewer->process(Product_Controller,Array,SSViewer_DataPresenter)
SSViewer.php:1273
SSViewer::execute_template(Head,Product_Controller,Array,SSViewer_DataPresenter)
.cache.themes.express.templates.Page.ss:2
include(/var/www/jackon.no/silverstripe-cache/www-data-php7.0.30-0ubuntu0.16.04.1/.cache.themes.express.templates.Page.ss)
SSViewer.php:1172
SSViewer->includeGeneratedTemplate(/var/www/jackon.no/silverstripe-cache/www-data-php7.0.30-0ubuntu0.16.04.1/.cache.themes.express.templates.Page.ss,Product_Controller,,Array,)
SSViewer.php:1234
SSViewer->process(Product_Controller)
Controller.php:201
Controller->handleAction(SS_HTTPRequest,index)
RequestHandler.php:208
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:151
Controller->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:174
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:154
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:154
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ModelAsController.php:75
ModelAsController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:385
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:149
Director::direct(/bygg/jackon-thermomur/thermomur-350-super/,DataModel)
main.php:194
There is only one page out of many not working and when I try to see what the $MetaTags(false) outputs on one of the working pages it is three <link rel="alternate" ...> tags giving a link to the same page in three different languages.
I would love to get some help on how I can locate and fix the problem. I can't really understand how line 522 could go wrong with the if-conditional in line 519.
The page does have a parent and looks exactly the same as a page with the same parent except for changes in the content like text.

Object of class stdClass could not be converted to string ERROR

I am trying to pass a value from my database to an input, but I throw the following error.I'm not sure if for this case you should use return $ this-> db-> get () -> row (); in the model. Any help is welcome.
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: usuarios/vConsulta_Horarios.php
Line Number: 590
Backtrace:
File: C:\xampp\htdocs\SAE\application\views\usuarios\vConsulta_Horarios.php
Line: 590
Function: _error_handler
File: C:\xampp\htdocs\SAE\application\controllers\cCalendar.php
Line: 26
Function: view
File: C:\xampp\htdocs\SAE\index.php
Line: 315
Function: require_once
Model (mCalendar)
public function lunes(){
$this->db->select('MIN(horario.hrs_ini)');
$this->db->from('horario');
$this->db->join('usuarios','horario.rut_usu = usuarios.rut_usu');
$this->db->where('usuarios.rut_usu','17811942-4');
$this->db->where('horario.lunes','ATTE. ESTUDIANTES');
return $this->db->get()->row();
Controller (cCalendar)
public function index(){
$this->load->view('layouts/header.php');
$this->load->view('layouts/menu.php');
$this->load->model('mCalendar');
$data['start_lunes'] = $this->mCalendar->lunes();
$this->load->view('usuarios/vConsulta_Horarios.php',$data);
$this->load->view('layouts/footer.php');
}
View
<div class="col-md-2">
<div class="form-group">
<label>fecha</label>
<input tupr="text" id="fecha_actual" name="fecha_actual" value="<?php echo $start_lunes;?>">
</div>
</div>
Even though you are only selecting one column, you still need to specify it when you output, because $start_lunes is the object that represents the entire row, and as the error tells you, it can't be converted to a string.
I think echo $start_lunes->hrs_ini should work.
Based on your updated function, I think it would be easier if you aliased the MIN expression in your select
$this->db->select('MIN(horario.hrs_ini) AS min_hrs');
Then refer to that in your view: echo $start_lunes->min_hrs
As return $this->db->get()->row(); returns object you are getting this error
You need to refer this link
So now, I will suggest you one thing to return data properly.
In your Controller change return $this->db->get()->row();
to
return $this->db->get()->result_array();
Now you are getting data in the format of Array and you can echo this in your View using
// In your view
foreach($start_lunes as $var){
$value = $var['MIN(horario.hrs_ini)'];
}
<input type="text" id="fecha_actual" name="fecha_actual" value="<?php echo $value?>"

Magento : Fatal error: Call to a member function getMethodInstance() on a non-object

Login Admin > sales > orders and I click view some order show detail but some order show error
Fatal error: Call to a member function getMethodInstance() on a
non-object in
/home/easter13/public_html/app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
on line 96
help me please, And thank you.
This is happning because there is a problem with your mail configuration. I have 2 suggestions:
1. Open app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
at line number 92 replace your code with below code:
if ($this->_isAllowedAction('emails') && !$order->isCanceled()) {
$confirmationMessage = $coreHelper->jsQuoteEscape(
Mage::helper('sales')->__('Are you sure you want to send order email to customer?')
);
$this->addButton('send_notification', array(
'label' => Mage::helper('sales')->__('Send Email'),
'onclick' => "confirmSetLocation('{$confirmationMessage}', '{$this->getEmailUrl()}')",
));
}
Then clear your cache, refresh the page and see if your error is gone.
2. Open app/code/core/Mage/Adminhtml/Block/Sales/Order/View.php
at line number 92, uncomment this code and then clear your cache,
refresh the page and check whether your error is gone.

Fatal error: Invalid template

i am new to PHP and it seems i ran into some deathcode.
Error given:
( ! ) Fatal error: Invalid template: FPage in /home/jharvard/vhosts/localhost/includes/functions.php on line 218
Call Stack
# Time Memory Function Location
1 0.0001 124636 {main}( ) ../buy.php:0
2 1.3034 144340 render( ) ../buy.php:6
3 1.3035 144476 trigger_error ( ) ../functions.php:218
This is as soon as i POST to my form at Buy.php
<?php
require("../includes/config.php");
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$symbol = $_POST["symbol"];
$price = lookup($symbol)["price"];
render("FPage", ["price" => $price]);
}
else{render("BuyPage.php");}
?>
BuyPage and FPage are respectively:
<form action="buy.php" method='post'><input name="symbol"><input name="SAmount"><input type="submit"></form>
and
<?php
echo $price;
?>
And functions.php(If need be) is at http://pastebin.com/Kd9Zg32S
What i was going for:
Pretty much a simple program to "buy" fake stocks for a programming challange. Lookup pretty much looks up a stock's symbol on yahoo finance and returns a list.
Render pretty much renders the template along with header and footer as well as extracting and inputting any variables passed in.
However about half way around the place i get struck here with a "hairball" of bugs, and this one i just cant seem to pass by.
Debugging help is highly appreciated.
Ps: Config is just a file that checks if the user is logged in, loading in functions e.t.c e.t.c, i brought in all the code that i thought was needed, if more is needed please notify me.
...
render("FPage", ["price" => $price]);
}
else{render("BuyPage.php");}
...
You render "FPage" and "BuyPage.php"
"BuyPage.php" works but FPage does not.
Try replacing "FPage" by "FPage.php".

Categories