View Single Post
  #44  
Old 04-10-2014, 10:47 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Webinar for X-Cart 5 developers on March,18th.

Hi Mike!

Sorry for being silent for a while.

1) The following test script will show you how you can get the category name by ID:

PHP Code:
<?php

require_once 'top.inc.php';

$category = \XLite\Core\Database::getRepo('\XLite\Model\Category')->find(2);

echo 
$category->getName();

This code must be put into PHP script in the root folder of X-Cart 5. You can see the whole process here. We are pulling a category object from repository and then calling getName() out of it to get name. You can call methods get<PROPERTY NAME> to any property of the object like getId(), getBody() and so on.

These getters are added automatically during cache rebuild process and you do not have to create them manually.

2) If you define the method that returns the category object in the controller and call it getDropDownObject, then you can output its name in your template as:

{getDropDownObject.name}

or

{getDropDownObject.getName()} if you want to call as a method of this object

or

{getDropDownObject.getName():h} if you want to allow HTML tags.

Please, let me know if it helps.

Tony.

Quote:
Originally Posted by totaltec
Tony,
I have made some progress on this issue, I edited XLite\Module\Baby\DropDown\Controller\Admin and added this code:
Code:
/** * Get parent name * * @return string */ public function getParentName() { $parent_id = $this->getParent_Id(); $parent = \XLite\Core\Database::getRepo('\XLite\Module\Baby\DropDown\Model\DropDown')->findOneById($parent_id); $parentName = $parent->name; return $parentName; }
At least now I can echo the name to myself, I need to figure out how best to use it in the template next.
Reply With Quote