Magento 2.4: create CSV File for each order placed - magento2

I am new to magento. I need to automatically create a csv file whenever an order is placed by the customer.
I am using the event "sales_order_place_after" but the code in the observer is not working.
Can anyone guide me how to generate the csv file successfully whenever the order gets placed.
i keep getting errors like: Object of class Magento\Sales\Model\Order\Address could not be converted to string
Class Order implements ObserverInterface
{
protected $_request;
protected $_order;
protected $_productRepository;
protected $_scopeConfig;
protected $_customer;
protected $_storemanager;
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Sales\Model\Order $order,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
Filesystem $filesystem,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Customer\Model\Customer $customer,
\Magento\Store\Model\StoreManagerInterface $storemanager,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Framework\ObjectManager\ObjectManager $objectManager,
\Psr\Log\LoggerInterface $logger,
\Magento\Catalog\Model\ProductFactory $productFactory,
\Magento\Catalog\Model\ProductRepository $productRepository
) {
$this->_scopeConfig = $scopeConfig;
$this->_customer = $customer;
$this->_storemanager = $storemanager;
$this->_request = $request;
$this->_order = $order;
$this->_fileFactory = $fileFactory;
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$this->_productRepository = $productRepository;
}
public function execute(\Magento\Framework\Event\Observer $observer) {
$order = $observer->getEvent()->getOrder();
$websiteID = $this->_storemanager->getStore()->getWebsiteId();
$headers = array( 'Customer Name', 'Customer Email', ' Phone','Shipping Address' ,'SKU','Quantity','Price','Total','Weight');
$name = strtotime('now');
$file = 'customorderexport/'.$name.'_detailed_orderexport.csv';
$this->directory->create('customorderexport');
$stream = $this->directory->openFile($file, 'w+');
$stream->lock();
$stream->writeCsv($headers);
// $orderdetail['Customer Name'] =
$orderdetail['Customer Email'] = $order->getCustomerEmail();
$orderdetail['Contact Phone'] = $order->getTelephone();
$orderdetail['Shipping Address'] = $order->getShippingAddress();
$items = $order->getAllItems();
foreach ($items as $item) {
$orderdetail['SKU'] = $item->getSKU();
$orderdetail['Quantity'] = $item->getQtyOrdered();
$orderdetail['Price'] = $item->getPrice();
$orderdetail['Total'] = $item->getGrandTotal();
$orderdetail['Weight'] = $item->getWeight();
$stream->writeCsv($orderdetail);
}
$stream->unlock();
$stream->close();
}
}

This is because
$order->getShippingAddress();
will return a OrderAddressInterface object. (Magento\Sales\Api\Data\OrderAddressInterface)
You could do following for example:
$shippingAddress = $order->getShippingAddress();
$orderdetail['Shipping Address'] = $shippingAddress->getStreet()[0];

Related

How to Get Child Product Ids from a Configurable product

I am trying to fetch all child product Ids from configurable product Ids.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('\Magento\Catalog\Model\Product');
$storeManager = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStore = $storeManager->getStore();
$mediaUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$productURL = $mediaUrl.'catalog/product';
$collection = $this->_productCollectionFactory->create();
$productCollection = $collection->addAttributeToSelect('*')->addAttributeToFilter('type_id','configurable');
$vendor_product = array();
$productData = $product->getData();
foreach($productCollection as $prodObj){
$productData = array();
$product = $product->load($prodObj->getId());
$productTypeInstance = $product->getTypeInstance();
$usedProducts = $productTypeInstance->getUsedProducts($product);
foreach ($usedProducts as $child) {
$productData['childrenIds'][] = $child->getId();
}
I get Ids of my first configurable product in all the cases
<?php
namespace Vendor\Module\Block;
class ParentAndChilds extends \Magento\Framework\View\Element\Template
{
/**
* #var Context
*/
protected $context;
/**
* #var ProductRepositoryInterface
*/
protected $productRepository;
/**
* #var SearchCriteriaBuilder
*/
protected $searchCriteriaBuilder;
/**
* #var LinkManagementInterface
*/
protected $linkManagement;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\ConfigurableProduct\Api\LinkManagementInterface $linkManagement,
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
array $data = []
)
{
$this->linkManagement = $linkManagement;
$this->productRepository = $productRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
parent::__construct($context, $data);
}
public function getParentsAndChilds()
{
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('type_id', 'configurable')
->create();
$configurableProducts = $this->productRepository
->getList($searchCriteria);
$parentAndChildProducts = array();
foreach ($configurableProducts->getItems() as $configurableProduct) {
$childProducts = $this->linkManagement
->getChildren($configurableProduct->getSku());
foreach ($childProducts as $childProduct) {
$parentAndChildProducts[$configurableProduct->getId()][] = $childProduct->getId();
}
}
return $parentAndChildProducts;
}
}
To get child product Ids from a configurable product, you can use below code:
public function __construct(
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
$this->productRepository = $productRepository;
}
public function execute()
{
$_productId=57786;
$_product=$this->productRepository->getById($_productId);
$childIs=$_product->getExtensionAttributes()->getConfigurableProductLinks();
print_r($childIs);
}
Output looks like:
Array
(
[31981] => 31981
[31982] => 31982
[31983] => 31983
)
Hope it will help you.
$_children = $_product->getTypeInstance()->getUsedProducts($_product);
foreach ($_children as $child){
$childProducts[] = $child;
}
$_product is the configurable product object
You can use the below code for getting Child ID.
$product = $block->getProduct();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$configurable_product_id = $product->getId();
$configurableProduct = $objectManager->get('Magento\Catalog\Model\ProductRepository')->getById($configurable_product_id);
$children = $configurableProduct->getTypeInstance()->getUsedProducts($configurableProduct); $childIds = array();
foreach ($children as $child){
$childIds[] = $child->getId();
}
sort($childIds);
print_r($childIds);
This is for sample code but I suggest do not use $objectManager directly, you can use Block on Plugin Method to get Product Object.
To get all simple children including out of stock products use:
$children = $product
->getTypeInstance()
->getChildrenIds($product->getId());
print_r($children);

Zend_Paginator for Categories

I have used Zend_Paginator in my Index action , this show all my catalog :
public function indexAction()
{
Zend_View_Helper_PaginationControl::setDefaultViewPartial('/pagination.phtml');
$pages = new Application_Model_DbTable_Catalog();
$num = 10;
$page = $this->_getParam('page');
$select = $pages->select();
$result = $this->view->table = $pages->fetchAll($select)->toArray();
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($result));
$paginator->setItemCountPerPage($num);
$paginator->setCurrentPageNumber($page);
$paginator->setView($this->view);
$this->view->paginator = $paginator;
}
It works perfectly, now I have CategoryAction, it's sort my catalog by category
public function categoryAction()
{
$id = intval($this->_getParam('id', 0));
if ($id > 0) {
$catalog = new Application_Model_DbTable_Catalog();
$this->view->catalog = $catalog->getByCategoryId($id);
и
$category = new Application_Model_DbTable_Categories();
$this->view->category = $category->getById($id);
}
So I can't understand how to add Pagination to this action,
Help me, Pleaaasssseeeeeee:-(,
P.S. sorry for my bad English
Ok there is a better/easier way to do this.
Pagination starts with your database query. You are using DbTable models so it's very easy in ZF1 to setup the adapter.
<?php
class Application_Model_DbTable_Catalog extends Zend_Db_Table_Abstract
{
protected $_name = 'catalog'
/*
* This method returns a paginator adapter with a fetchAll($where = null, $order = null, $count = null, $offset = null)
* paginator adapter will supply the values for $offset and $limit
*/
public function getPagedCatalog()
{
$select = $this->select(); //put anything you need into $select
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);//the paginator adapter in place of the fetchAll().
return $adapter;
{
}
<?php
class Application_Model_DbTable_Categories extends Zend_Db_Table_Abstract
{
protected $_name = 'categories'
/*
* This method returns a paginator adapter with a fetchAll($where = $id, $order = null, $count = null, $offset = null)
* paginator adapter will supply the values for $offset and $limit
*/
public function getPagedCatagories($id)
{
$select = $this->select(); //put anything you need into $select
$select->where('catagory_id = ?', $id);//you may need to build a join for this to work how you want it to, depends on your table structure.
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);//the paginator adapter in place of the fetchAll().
return $adapter;
{
}
now your models will return paginator adapters with the contents of these tables available. Zend_Paginator will automatically supply the $limit and $offset parameters to the query so that each page will perform a query. The whole table will not be stored in memory with this adapter.
Now your indexAction() may look like:
public function indexAction()
{
Zend_View_Helper_PaginationControl::setDefaultViewPartial('/pagination.phtml');
$pages = new Application_Model_DbTable_Catalog();
$adapter = $pages->getPagedCatalog(); //get adapter from model
$page = $this->_getParam('page', 1);//a default of page 1 prevents possible unusual behavior when no page number is set.
$paginator = new Zend_Paginator($adapter);
$paginator->setItemCountPerPage('10');
$paginator->setCurrentPageNumber($page);
//$paginator->setView($this->view); This line is likely not needed
$this->view->paginator = $paginator;
}
and your categoryAction() might work like:
public function categoryAction()
{
$page = $this->_getParam('page', 1);
$id = intval($this->_getParam('id', 0));
if ($id > 0) {
$category = new Application_Model_DbTable_Categories();
$adapter = $category->getPagedCatagories($id);
//same as above
$paginator = new Zend_Paginator($adapter);
$paginator->setItemCountPerPage('10');
$paginator->setCurrentPageNumber($page);
//$paginator->setView($this->view); This line is likely not needed, unless you have multiple view objects.
$this->view->paginator = $paginator;
} else {
//do some other stuff...
}
}
if you get crazy and want to use your own mapper classes to base a paginator adapter on you can extend the adapter class by overriding getItems(), something like:
<?php
class Music_Model_Paginator_Track extends Zend_Paginator_Adapter_DbTableSelect
{
//override getItems()
public function getItems($offset, $itemCountPerPage)
{
$rows = parent::getItems($offset, $itemCountPerPage);
$albums = array();
foreach ($rows as $row) {
$album = new Music_Model_Mapper_Track();//use this class to turn each $row into an object
$albums[] = $album->createEntity($row); //build the new entity objects
}
//returns an array of entity objects to the paginator
return $albums;
}
}
Hope this helps.

How to use locale in select query in Zend model

On my administrator cms I can add newsitems and add a language code in column 'language' to the newsitem 'en' or 'nl'. In the bootstrapfile the language is set through:
public function _initLanguage()
{
$objSessionLanguage= new Zend_Session_Namespace('Zend_Lang');
$objLocale = new Zend_Locale();
$locale = new Zend_Locale();
$language = $locale->getLanguage();
$region = $locale->getRegion();
Zend_Loader::loadClass('Zend_Controller_Request_Http');
$request = new Zend_Controller_Request_Http();
if($language=='nl' or $language=='en')
{
if($language=='nl')
{
$localFile = 'dutch.php';
$Locale = 'nl';
}else
{ {
$localFile = 'english.php';
$Locale = 'en';
}
$objSessionLanguage->localFile=$localFile;
$objSessionLanguage->Locale=$Locale;
}else
{
if(!isset($objSessionLanguage->localFile))
{
$localFile = 'english.php';
$Locale = 'en';
}else
{
$localFile = $objSessionLanguage->localFile;
$Locale =$objSessionLanguage->Locale;
}
}
$objTranslate = new Zend_Translate('array', APPLICATION_PATH .'/../language/english.php', 'en');
$objTranslate->addTranslation(APPLICATION_PATH .'/../language/'.$localFile, $Locale);
$objTranslate->setLocale($Locale);
Zend_Registry::set("Zend_Translate", $objTranslate);
}
To display newsitems in a NewsList I want to select the newsitems in the newsmodel depending on language.
<?php
class Admin_Model_News extends Zend_Db_Table_Abstract
{
protected $_modelName = 'news';
protected $_modelLabel = 'News';
protected $_name = 'news';
protected $_objGeneralSettingVar;
public function init()
{
parent::init();
$this->_objGeneralSettingVar = Zend_Registry::get( "objGeneralSettingVar");
}
public function fetchNewsList()
{
$objSelect = $this->select()->limit(5);
$objSelect->where ("language = '$language'");
$objSelect->order("news_date DESC");
return $this->fetchAll($objSelect)->toArray();
}
}
But with the above
$objSelect->where ("language = '$language'");
no newsitems is displayed. I am sure I am missing something but can not seem to find it. How can I use the language setting in selecting newsitems on language?
In Admin_Model_News you are using
$objSelect->where ("language = '$language'");
for your where clause, but $language has not been set anywhere, so you are querying Where language = null.
The function fetchNewsList should look like this:-
public function fetchNewsList($language)
{
$objSelect = $this->select()->limit(5);
$objSelect->where ("language = '$language'");
$objSelect->order("news_date DESC");
return $this->fetchAll($objSelect)->toArray();
}
You don't show how you are using Admin_Model_News, but it should be something like this:-
$news = new Admin_Model_News();
$newList = $news->fetchNewsList(howeverYouGetlanguage());

Doctrine ODM (MongoDB) - Get a complete array of an object?

iv'e got a problem to receive a complete array (with all the data of the embedded childs collections and objects) of my document. My document looks exactly like this one:
use Doctrine\Common\Collections\ArrayCollection;
/** #Document(collection="user") */
class User {
/** #Id */
protected $id;
/** #String */
protected $firstname;
/** #String */
protected $lastname;
/** #EmbedMany(targetDocument="Email") */
protected $email;
/** #EmbedMany(targetDocument="Address") */
protected $address;
/** #EmbedMany(targetDocument="Subscription") */
protected $subscription;
/**
* Construct the user
*
* #param array $properties
* #throws User_Exception
*/
public function __construct(array $properties = array()) {
$this->email = new ArrayCollection();
$this->address = new ArrayCollection();
$this->subscription = new ArrayCollection();
foreach($properties as $name => $value){
$this->{$name} = $value;
}
}
...
I need a complete array of an embedded collection to output the whole data and render it by json. My query looks like this:
$query = $this->_dbContainer->getDocumentManager()->createQueryBuilder('User')->field('deletedAt')->exists(false);
$result = $query->field('id')->equals($id)->getQuery()->getSingleResult();
For example, if i call the toArray() function like this:
$array = $result->getSubscription()->toArray();
print_r($array);
Then the output ist just an array on top level:
[0] => Object Subscription...
[1] => Object Subscription...
...
How can i easily get an array like this?
[0] => array('subscriptionLabel' => 'value1', 'field' => 'value1', ...)
[1] => array('subscriptionLabel' => 'value2', 'field' => 'value2', ...)
...
Are there any best practises or maybe some missing helper scripts to prevent something ugly like this code (how to handle child -> child -> child szenarios? ugly -> ugly ugly -> ugly ugly ugly -> ...):
$example = array();
foreach($result->getSubscription() as $key => $subscription) {
$example[$key]['subscriptionLabel'] = $subscription->getSubscriptionLabel();
$example[$key]['field'] = $subscription->getField();
...
}
Thanks a lot,
Stephan
Damn simple answer! Just use ->hydrate(false) and it's done.
For find queries the results by
default are hydrated and you get
document objects back instead of
arrays. You can disable this and get
the raw results directly back from
mongo by using the hydrate(false)
method:
<?php
$users = $dm->createQueryBuilder('User')
->hydrate(false)
->getQuery()
->execute();
print_r($users);
I ran into this same need recently and solved it by creating a base class for all my entities with a toArray() function and JsonSerializable. It converts all nested references as well.
/**
* #ODM\MappedSuperclass
*/
abstract class BaseDocument implements \JsonSerializable
{
public function jsonSerialize() {
return $this->toArray();
}
public function toArray() {
$getter_names = get_class_methods(get_class($this));
$gettable_attributes = array();
foreach ($getter_names as $key => $funcName) {
if(substr($funcName, 0, 3) === 'get') {
$propName = strtolower(substr($funcName, 3, 1));
$propName .= substr($funcName, 4);
$value = $this->$funcName();
if (is_object($value) && get_class($value) == 'Doctrine\ODM\MongoDB\PersistentCollection') {
$values = array();
$collection = $value;
foreach ($collection as $obj) {
$values[] = $obj->toArray();
}
$gettable_attributes[$propName] = $values;
}
else {
$gettable_attributes[$propName] = $value;
}
}
}
return $gettable_attributes;
}
}
Now I can serialize the entity as an array or json string with json_encode($doc). Bam.
Tanks to Rooster242, you can even recursively apply toArray to embedded documents which themself extends BaseDocument by using the php is_subclass_of function :
/**
* #ODM\MappedSuperclass
*/
abstract class BaseDocument implements \JsonSerializable
{
public function jsonSerialize() {
return $this->toArray();
}
public function toArray() {
$getter_names = get_class_methods(get_class($this));
$gettable_attributes = array();
foreach ($getter_names as $key => $funcName) {
if(substr($funcName, 0, 3) === 'get') {
$propName = strtolower(substr($funcName, 3, 1));
$propName .= substr($funcName, 4);
$value = $this->$funcName();
if (is_object($value) && is_subclass_of($value,"BaseDocument")) {
$gettable_attributes[$propName] = $value->toArray();
} elseif (is_object($value) && get_class($value) == 'Doctrine\ODM\MongoDB\PersistentCollection') {
$values = array();
$collection = $value;
foreach ($collection as $obj) {
if (is_subclass_of($obj,"BaseDocument")) {
$values[] = $obj->toArray();
} else {
$values[] = $obj;
}
}
$gettable_attributes[$propName] = $values;
}
else {
$gettable_attributes[$propName] = $value;
}
}
}
return $gettable_attributes;
}
}
Just made this a bit more generic, works perfect. Just dont forget to extend it with your documents and embeds.
<?php
namespace App\Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\PersistentCollection;
/**
* #ODM\MappedSuperclass
*/
abstract class BaseDocument implements \JsonSerializable
{
/**
* #return array
*/
public function jsonSerialize()
{
return $this->toArray();
}
/**
* #return array
*/
public function toArray()
{
$getterNames = get_class_methods(get_class($this));
$gettableAttributes = [];
foreach ($getterNames as $funcName) {
if (substr($funcName, 0, 3) !== 'get') {
continue;
}
$propName = strtolower(substr($funcName, 3, 1));
$propName .= substr($funcName, 4);
$value = $this->$funcName();
$gettableAttributes[$propName] = $value;
if (is_object($value)) {
if ($value instanceof PersistentCollection) {
$values = [];
$collection = $value;
foreach ($collection as $obj) {
/** #var BaseDocument $obj */
if ($obj instanceof \JsonSerializable) {
$values[] = $obj->toArray();
} else {
$values[] = $obj;
}
}
$gettableAttributes[$propName] = $values;
} elseif ($value instanceof \JsonSerializable) {
/** #var BaseDocument $value */
$gettableAttributes[$propName] = $value->toArray();
}
}
}
return $gettableAttributes;
}
}

ZEND application not quite runnig while fresh SVN checkout

There's nothing I can say really, as I'm not into ZEND... All I can say is I get a stack of errors/warnings that look like :
Zend_Exception: No entry is registered for key 'liveHeader' in /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Registry.php on line 147 Call Stack: 0.0007 630840 1. {main}() /Users/koopa/Sites/ykone/trunk/public/index.php:0 0.2304 4603280 2. Zend_Application->run() /Users/koopa/Sites/ykone/trunk/public/index.php:42 0.2304 4603280 3. Bootstrap->run() /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Application.php:328 0.2346 4626200 4. Zend_Application_Bootstrap_Bootstrap->run() /Users/koopa/Sites/ykone/trunk/application/Bootstrap.php:12 0.2348 4626520 5. Zend_Controller_Front->dispatch($request = ???, $response = ???) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Application/Bootstrap/Bootstrap.php:77 1.6190 13445472 6. Zend_Controller_Plugin_Broker->postDispatch($request = class Zend_Controller_Request_Http { protected $_paramSources = array (0 => '_GET', 1 => '_POST'); protected $_requestUri = '/'; protected $_baseUrl = ''; protected $_basePath = NULL; protected $_pathInfo = '/'; protected $_params = array ('controller' => 'index', 'action' => 'index'); protected $_aliases = array (); protected $_dispatched = TRUE; protected $_module = 'default'; protected $_moduleKey = 'module'; protected $_controller = 'index'; protected $_controllerKey = 'controller'; protected $_action = 'index'; protected $_actionKey = 'action' }) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Controller/Front.php:956 1.6191 13445472 7. Zend_Layout_Controller_Plugin_Layout->postDispatch($request = class Zend_Controller_Request_Http { protected $_paramSources = array (0 => '_GET', 1 => '_POST'); protected $_requestUri = '/'; protected $_baseUrl = ''; protected $_basePath = NULL; protected $_pathInfo = '/'; protected $_params = array ('controller' => 'index', 'action' => 'index'); protected $_aliases = array (); protected $_dispatched = TRUE; protected $_module = 'default'; protected $_moduleKey = 'module'; protected $_controller = 'index'; protected $_controllerKey = 'controller'; protected $_action = 'index'; protected $_actionKey = 'action' }) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Controller/Plugin/Broker.php:330 1.6193 13445976 8. Zend_Layout->render($name = ???) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Layout/Controller/Plugin/Layout.php:142 1.6203 13450944 9. Zend_View_Abstract->render($name = 'layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Layout.php:791 1.6204 13492584 10. Zend_View->_run('/Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/View/Abstract.php:832 1.6215 13653240 11. include('/Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/View.php:107 1.7286 15289440 12. YPush->LayoutTop() /Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml:153 1.7286 15289704 13. YPush->__call($method = 'LayoutTop', $attr = array ()) /Users/koopa/Sites/ykone/trunk/library/YPush.php:153 1.7295 15336024 14. YPush->getData() /Users/koopa/Sites/ykone/trunk/library/YPush.php:79 1.7295 15336024 15. YPush->loadData() /Users/koopa/Sites/ykone/trunk/library/YPush.php:122 1.7295 15336544 16. call_user_func_array(array (0 => class YPush_LayoutTop { private ${YPush}:_file = 'layouttop.php'; protected $_dir = ''; protected $_class = 'YPush'; protected $_attr = array (...); protected $_cache = FALSE; protected $_lifetime = 86400; private ${YPush}:_id = 'LayoutTop_2723407904'; public $request = class Zend_Controller_Request_Http { ... }; private ${Zend_View}:_useViewStream = FALSE; private ${Zend_View}:_useStreamWrapper = FALSE; private ${Zend_View_Abstract}:_path = array (...); private ${Zend_View_Abstract}:_file = NULL; private ${Zend_View_Abstract}:_helper = array (...); private ${Zend_View_Abstract}:_helperLoaded = array (...); private ${Zend_View_Abstract}:_helperLoadedDir = array (...); private ${Zend_View_Abstract}:_filter = array (...); private ${Zend_View_Abstract}:_filterClass = array (...); private ${Zend_View_Abstract}:_filterLoaded = array (...); private ${Zend_View_Abstract}:_filterLoadedDir = array (...); private ${Zend_View_Abstract}:_escape = 'htmlspecialchars'; private ${Zend_View_Abstract}:_encoding = 'ISO-8859-1'; private ${Zend_View_Abstract}:_lfiProtectionOn = TRUE; private ${Zend_View_Abstract}:_loaders = array (...); private ${Zend_View_Abstract}:_loaderTypes = array (...); private ${Zend_View_Abstract}:_strictVars = FALSE; private ${Zend_View_Abstract}:_log = NULL }, 1 => 'prepare'), array ()) /Users/koopa/Sites/ykone/trunk/library/YPush.php:132 1.7295 15336792 17. YPush_LayoutTop->prepare() /Users/koopa/Sites/ykone/trunk/library/YPush.php:132 1.7295 15336872 18. Zend_Registry::get($index = 'liveHeader') /Users/koopa/Sites/ykone/trunk/library/YPush/LayoutTop.php:15 Variables in local scope (#18): $index = 'liveHeader' $instance = class Zend_Registry { public $Zend_View_Helper_Placeholder_Registry = class Zend_View_Helper_Placeholder_Registry { protected $_containerClass = 'Zend_View_Helper_Placeholder_Container'; protected $_items = array (...) }; public $db = class Zend_Db_Adapter_Pdo_Mysql { protected $_pdoType = 'mysql'; protected $_numericDataTypes = array (...); protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo'; protected $_config = array (...); protected $_fetchMode = 2; protected $_profiler = class Zend_Db_Profiler { ... }; protected $_defaultProfilerClass = 'Zend_Db_Profiler'; protected $_connection = class PDO { ... }; protected $_caseFolding = 0; protected $_autoQuoteIdentifiers = TRUE; protected $_allowSerialization = TRUE; protected $_autoReconnectOnUnserialize = FALSE }; public $db_master = class Zend_Db_Adapter_Pdo_Mysql { protected $_pdoType = 'mysql'; protected $_numericDataTypes = array (...); protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo'; protected $_config = array (...); protected $_fetchMode = 2; protected $_profiler = class Zend_Db_Profiler { ... }; protected $_defaultProfilerClass = 'Zend_Db_Profiler'; protected $_connection = class PDO { ... }; protected $_caseFolding = 0; protected $_autoQuoteIdentifiers = TRUE; protected $_allowSerialization = TRUE; protected $_autoReconnectOnUnserialize = FALSE }; public $Zend_Locale = class Zend_Locale { protected $_locale = 'fr' }; public $WideLocale = 'fr_FR'; public $UrlTranslator = class Zend_Translate { private $_adapter = class Zend_Translate_Adapter_Csv { ... } }; public $config = class Zend_Config_Ini { protected $_nestSeparator = '.'; protected $_sectionSeparator = ':'; protected $_skipExtends = FALSE; protected $_allowModifications = FALSE; protected $_index = 0; protected $_count = 8; protected $_data = array (...); protected $_skipNextIteration = NULL; protected $_loadedSection = array (...); protected $_extends = array (...); protected $_loadFileErrorStr = NULL }; public $Zend_View_Helper_Doctype = class ArrayObject { public $doctypes = array (...); public $doctype = 'HTML4_LOOSE' } } Zend_Exception: No entry is registered for key 'liveLogo' in /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Registry.php on line 147 Call Stack: 0.0007 630840 1. {main}() /Users/koopa/Sites/ykone/trunk/public/index.php:0 0.2304 4603280 2. Zend_Application->run() /Users/koopa/Sites/ykone/trunk/public/index.php:42 0.2304 4603280 3. Bootstrap->run() /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Application.php:328 0.2346 4626200 4. Zend_Application_Bootstrap_Bootstrap->run() /Users/koopa/Sites/ykone/trunk/application/Bootstrap.php:12 0.2348 4626520 5. Zend_Controller_Front->dispatch($request = ???, $response = ???) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Application/Bootstrap/Bootstrap.php:77 1.6190 13445472 6. Zend_Controller_Plugin_Broker->postDispatch($request = class Zend_Controller_Request_Http { protected $_paramSources = array (0 => '_GET', 1 => '_POST'); protected $_requestUri = '/'; protected $_baseUrl = ''; protected $_basePath = NULL; protected $_pathInfo = '/'; protected $_params = array ('controller' => 'index', 'action' => 'index'); protected $_aliases = array (); protected $_dispatched = TRUE; protected $_module = 'default'; protected $_moduleKey = 'module'; protected $_controller = 'index'; protected $_controllerKey = 'controller'; protected $_action = 'index'; protected $_actionKey = 'action' }) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Controller/Front.php:956 1.6191 13445472 7. Zend_Layout_Controller_Plugin_Layout->postDispatch($request = class Zend_Controller_Request_Http { protected $_paramSources = array (0 => '_GET', 1 => '_POST'); protected $_requestUri = '/'; protected $_baseUrl = ''; protected $_basePath = NULL; protected $_pathInfo = '/'; protected $_params = array ('controller' => 'index', 'action' => 'index'); protected $_aliases = array (); protected $_dispatched = TRUE; protected $_module = 'default'; protected $_moduleKey = 'module'; protected $_controller = 'index'; protected $_controllerKey = 'controller'; protected $_action = 'index'; protected $_actionKey = 'action' }) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Controller/Plugin/Broker.php:330 1.6193 13445976 8. Zend_Layout->render($name = ???) /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Layout/Controller/Plugin/Layout.php:142 1.6203 13450944 9. Zend_View_Abstract->render($name = 'layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/Layout.php:791 1.6204 13492584 10. Zend_View->_run('/Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/View/Abstract.php:832 1.6215 13653240 11. include('/Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml') /Users/koopa/Sites/ykone/trunk/ZF/library/Zend/View.php:107 1.7286 15289440 12. YPush->LayoutTop() /Users/koopa/Sites/ykone/trunk/application/views/scripts/layout.phtml:153 1.7286 15289704 13. YPush->__call($method = 'LayoutTop', $attr = array ()) /Users/koopa/Sites/ykone/trunk/library/YPush.php:153 1.7295 15336024 14. YPush->getData() /Users/koopa/Sites/ykone/trunk/library/YPush.php:79 1.7295 15336024 15. YPush->loadData() /Users/koopa/Sites/ykone/trunk/library/YPush.php:122 1.7295 15336544 16. call_user_func_array(array (0 => class YPush_LayoutTop { private ${YPush}:_file = 'layouttop.php'; protected $_dir = ''; protected $_class = 'YPush'; protected $_attr = array (...); protected $_cache = FALSE; protected $_lifetime = 86400; private ${YPush}:_id = 'LayoutTop_2723407904'; public $request = class Zend_Controller_Request_Http { ... }; private ${Zend_View}:_useViewStream = FALSE; private ${Zend_View}:_useStreamWrapper = FALSE; private ${Zend_View_Abstract}:_path = array (...); private ${Zend_View_Abstract}:_file = NULL; private ${Zend_View_Abstract}:_helper = array (...); private ${Zend_View_Abstract}:_helperLoaded = array (...); private ${Zend_View_Abstract}:_helperLoadedDir = array (...); private ${Zend_View_Abstract}:_filter = array (...); private ${Zend_View_Abstract}:_filterClass = array (...); private ${Zend_View_Abstract}:_filterLoaded = array (...); private ${Zend_View_Abstract}:_filterLoadedDir = array (...); private ${Zend_View_Abstract}:_escape = 'htmlspecialchars'; private ${Zend_View_Abstract}:_encoding = 'ISO-8859-1'; private ${Zend_View_Abstract}:_lfiProtectionOn = TRUE; private ${Zend_View_Abstract}:_loaders = array (...); private ${Zend_View_Abstract}:_loaderTypes = array (...); private ${Zend_View_Abstract}:_strictVars = FALSE; private ${Zend_View_Abstract}:_log = NULL }, 1 => 'prepare'), array ()) /Users/koopa/Sites/ykone/trunk/library/YPush.php:132 1.7295 15336792 17. YPush_LayoutTop->prepare() /Users/koopa/Sites/ykone/trunk/library/YPush.php:132 1.7307 15371992 18. Zend_Registry::get($index = 'liveLogo') /Users/koopa/Sites/ykone/trunk/library/YPush/LayoutTop.php:21 Variables in local scope (#18): $index = 'liveLogo' $instance = class Zend_Registry { public $Zend_View_Helper_Placeholder_Registry = class Zend_View_Helper_Placeholder_Registry { protected $_containerClass = 'Zend_View_Helper_Placeholder_Container'; protected $_items = array (...) }; public $db = class Zend_Db_Adapter_Pdo_Mysql { protected $_pdoType = 'mysql'; protected $_numericDataTypes = array (...); protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo'; protected $_config = array (...); protected $_fetchMode = 2; protected $_profiler = class Zend_Db_Profiler { ... }; protected $_defaultProfilerClass = 'Zend_Db_Profiler'; protected $_connection = class PDO { ... }; protected $_caseFolding = 0; protected $_autoQuoteIdentifiers = TRUE; protected $_allowSerialization = TRUE; protected $_autoReconnectOnUnserialize = FALSE }; public $db_master = class Zend_Db_Adapter_Pdo_Mysql { protected $_pdoType = 'mysql'; protected $_numericDataTypes = array (...); protected $_defaultStmtClass = 'Zend_Db_Statement_Pdo'; protected $_config = array (...); protected $_fetchMode = 2; protected $_profiler = class Zend_Db_Profiler { ... }; protected $_defaultProfilerClass = 'Zend_Db_Profiler'; protected $_connection = class PDO { ... }; protected $_caseFolding = 0; protected $_autoQuoteIdentifiers = TRUE; protected $_allowSerialization = TRUE; protected $_autoReconnectOnUnserialize = FALSE }; public $Zend_Locale = class Zend_Locale { protected $_locale = 'fr' }; public $WideLocale = 'fr_FR'; public $UrlTranslator = class Zend_Translate { private $_adapter = class Zend_Translate_Adapter_Csv { ... } }; public $config = class Zend_Config_Ini { protected $_nestSeparator = '.'; protected $_sectionSeparator = ':'; protected $_skipExtends = FALSE; protected $_allowModifications = FALSE; protected $_index = 0; protected $_count = 8; protected $_data = array (...); protected $_skipNextIteration = NULL; protected $_loadedSection = array (...); protected $_extends = array (...); protected $_loadFileErrorStr = NULL }; public $Zend_View_Helper_Doctype = class ArrayObject { public $doctypes = array (...); public $doctype = 'HTML4_LOOSE' } }
Any help really appreciated.
You call Zend_Registry::get('liveHeader') before Zend_Registry::set('liveHeader', $liveHeader) which is wrong. Zend_Registry is a global singelton which behaves much like an array, similar to a plain php variant:
$liveHeader = ....
$registry = array('liveHeader' => $liveHeader);