Trying to get params from list in joomla - joomla

I have a joomla 3 module. It works great. I want to add parameters in the administration section that I can then use in the tmpl->default.php file, but I'm struggling to find out how to do it.
I have in my XML file:
<config>
<fields name="params">
<fieldset name="basic">
<field
name="show_category"
type="list"
label="What to display"
description="What to display"
default="">
<option value="0">Day/Time/Event</option>
<option value="1">Day/Time/Event/Description</option>
</field>
</fieldset>
</fields>
</config>
and then in my default.php file:
<?php defined('_JEXEC') or die;
$module = JModuleHelper::getModule('mod_calendar_ajax_google');
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);
$param = $moduleParams->get('show_category', '');
$dashboardID = $param['show_category'];
but is doesn't work.

Better not to call params directly in default.php file rather you can call params in your mod_calendar_ajax_google.php file like this
$category = $params->get('show_category','Day/Time/Event');
This will give the name if it is set in your options, else it gives the default value Day/Time/Event.
To call it in your default.php file, you can directly call $category. Hope I made myself clear.
If at all you need to call param directly from anywhere in joomla you need to remove last line. It should only be this
$module = JModuleHelper::getModule('mod_calendar_ajax_google');
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);
$dashboardID = $moduleParams->get('show_category', '');

Example:
You have module "mod_calendar_ajax_google". Then you need next files structure:
-mod_calendar_ajax_google.xml
-mod_calendar_ajax_google.php
-helper.php
-tmpl (folder)
--default.php
Code mod_calendar_ajax_google.php
<?php
defined('_JEXEC') or die;
require_once dirname(__FILE__).'/helper.php';
$data = modCalendarAjaxGoogleHelper::getData($params);
require JModuleHelper::getLayoutPath('mod_calendar_ajax_google', $params->get('layout', 'default'));
Code helper.php
<?php
defined('_JEXEC') or die;
class modCalendarAjaxGoogleHelper {
public static function getData(&$params) {
$data = $params->get('show_category');
return $data;
}
}
Code default.php
<?php
defined('_JEXEC') or die;
print_r ($data); // <-- YOUR PARAMS

Related

How Do I Output Multiselect Attribute Values In Magento 2.3.x?

In a Magento 2.3.3 store I am trying to ouput the values of a multiselect custom attribute on a category page, but not having any luck.
I have set the attribute to be used in product listing and tried to output it on catalog/product/listing.phtml template page in my custom theme.
I am using the using the following code:
<?php /* #escapeNotVerified */ echo $_product->getResource()->getAttribute('custom_attribute')->getFrontend()->getValue($_product); ?>
This is working for dropdown attributes but not multi select attributes.
Kind of stuck on this...
You can use the below code to get MultiSelect Attribute value
create block in "catalog_product_view.xml"
<referenceBlock name="product.info.main">
<block class="Magento\Catalog\Block\Product\View" name="attribue.name" template="Magento_Catalog::product/view/attribute_name.phtml" after="-" />
</referenceBlock>
create "phtml" file under "Magento_Catalog::product/view/attribute_name.phtml"
<?php $product = $block->getProduct(); ?>
<div>
<?php
$data = explode(',',$product->getData('attribute_code'));
foreach($data as $value):
?>
<?php
$attr = $product->getResource()->getAttribute('attribute_code');
if ($attr->usesSource()):
?>
<?php
$option_value = $attr->getSource()->getOptionText($value);
?>
<p><?php echo $option_value; ?></p>
<?php endif;?>
<?php endforeach;?>
</div>
Here is an example of a code that returns "Multiselect Attribute Values". The attribute belongs to product entity. As it isn't a good idea to get ProductResource model from ProductModel and taking into account that probably you need to get it inside some template, just create a ViewModel and use this example there.
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
...
public function __construct(
...
ProductResource $productResource
)
{
...
$this->productResource = $productResource;
}
public function prepareProductAttributeOptions($product, $attributeCode)
{
$result = [];
$data = $product->getData($attributeCode);
$optionsIds = [];
if ($data) {
$optionsIds = explode(',', $data);
}
foreach ($optionsIds as $optionId) {
$attr = $this->productResource->getAttribute($attributeCode);
if ($attr->usesSource()) {
$option_value = $attr->getSource()->getOptionText($optionId);
$result[] = $option_value;
}
}
return implode(',', $result);
}

dynamically page load using codeigniter

helow, I am a newbie in codeigniter. I want to load my pages into my view dynamically. That means, Using a function.
For example i have 4 page home, about, contact, info. In my my view folder I have created a base layout where i include header and footer which is same for all those pages. now i want when i click those page link it just load into content body without loading full page. Using CI normal procedure i can do it. which is
function home(){
$data['main_content'] = 'home';
$this->load->view('template/layout', $data);
}
function about(){
$data['main_content'] = 'about';
$this->load->view('template/layout', $data);
}
but i want to create a function which call this pages into a single function for example,
function pageload($page){
}
this function check that requested file either exits or not exist. if exist it load the page otherwise load "page not found" 404 error page. How can I make it...plz help.
My view file is:
<nav>
<ul class="sf-menu">
<li class="current"><?php echo anchor('home/index', 'Home');?></li>
<li><?php echo anchor('home/amenities', 'Room & Amenitis');?></li>
<li><?php echo anchor('home/reservations', 'Reservations');?></li>
<li><?php echo anchor('home/photos', 'Photographs');?></li>
<li><?php echo anchor('home/pakages', 'Pakages');?></li>
<li><?php echo anchor('home/explore', 'Explore');?></li>
<li><?php echo anchor('home/contact', 'Contact');?></li>
</ul>
</nav>
And Controller:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{
function __construct(){
parent::__construct();
}
function pageload($page){
$data['main_content'] = $page;
$this->load->view('template/layout', $data);
}
}
?>
You can do something lilke this
function pageload($page){
$data['main_content'] = $page;
$this->load->view('template/layout', $data);
}
if u dont want to show controller_name/pageload in url then in application/config/routes.php
add an array
$route['(home|about_us|other_page|another_page)'] = 'controller_name/pageload/$1';
and to load your 404 page just go to the application/config/routes.php
find this line $route['404_override'] and set its value to snything u want like
$route['404_override'] = 'page_not_found';
then in your controller just add a controller named page_not_found.php and load ur desired 404 custom view from that controller.
Try this function i think this will help you
function build_view($flake) {
$this->data['content'] = $this->load->view($flake, $this->data, TRUE);
$this->load->view('header', $this->data);
}
after you add this you need to add to other function like in index function
function index(){
$this->$data['main_content'] = $page;
$this->build_view('template/layout.php')
}

codeigniter: modify value in view from controller

I am trying to modified value from controller to view. I would like to achieve that when a user is signing up, and submited, I can return feedback from model to controller to view.
my view: main_view
<?php include('header.php'); ?>
<?php echo $sign_up_results ?>
<?php include('forms/forms.php'); ?>
<?php include('footer.php'); ?>
my controller
function __construct(){
parent::__construct();
$this->load->helper('url');
$template = $this->load->View('main_view');
}
function form_sign_up_controller(){
$this->load->model("form_sign_up");
$database_insert_results = $this->form_sign_up->insert_user_detail_into_db();
$data['sign_up_results']=$database_insert_results;
$template = $this->load->View('main', $data);
}
The problem is when the view is loaded, the value "$sign_up_results" is not yet defined. Is there anyway that I can define the value and then change the value according to the results return from model to controller.
just use is set to check if the parameter is defined or not
<?php if(isset($sign_up_results)) echo $sign_up_results ?>

Magento: list all values of a single attribute

I'm trying to list up all the existing values of a newly created attribute in magento 1.7.0.2.
(and make them clickable links, so that on click they list up all of the items with the specific attribute value, but that's not a priority right now)
The attribute code is "artist"
So far i created the file Artist.php in app/code/core/Mage/Catalog/Block/ with the following code:
public function getAllArtists()
{
$product = Mage::getModel('catalog/product');
$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter('attribute_code', 'artist');
$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
$artists = $attribute->getSource()->getAllOptions(false);
return $artists;
}
and the file artist.phtml in /app/design/frontend/default/template-name/template/catalog/product with this code:
<ul id="artist_list">
<?php foreach ($this->getAllArtists() as $artist): ?>
<li><?php echo $artist['label'] ?></li>
<?php endforeach; ?>
</ul>
which i then call in a static block with
{{block type="core/template" template="catalog/product/artist.phtml"}}
but nothing appears...
i used the code from this thread: http://www.magentocommerce.com/boards/viewthread/19982/P0/
the attribute is set "Visible on Product View Page on Front-end"
and i call the attribute value of each item in the ../template/product/view.phtml with
<?php echo $_product->getData('artist') ?>
and it correctly displays the value.
any ideas?
$name='whatever_your_attribute_name';
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
$attributeId = $attributeInfo->getAttributeId();
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute ->getSource()->getAllOptions(false);
print_r($attributeOptions);
Ref: Magento - get all attribute value
it will be just
$attribute = Mage::getModel('eav/config')->getAttribute(4,'artist');
if($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
foreach($options as $key=>$value) {
if(count($value)==2) {
$artists[] = $value['label'];
}
}
}

$data['main_content'] to load view in subfolder in CodeIgniter

Here is my function:
function single_resonator() {
$data['title'] = 'Single Resonator Operating Parameters';
$data['main_content'] = 'products/single_res_view';
$this->load->view('templates/main.php', $data);
}
But the single_res_view doesn't load if it is in the products folder in the views folder. How do I accomplish this? I tried a file called MY_router.php from a post elsewhere on this site and it didn't help. CI will only load the single_res_view if it is in the root of the views folder.
Here is templates/main.php
<?php $this->load->view('includes/header.php'); ?>
<?php $this->load->view('includes/nav.php'); ?>
<?php $this->load->view($main_content); ?>
<?php $this->load->view('includes/footer.php'); ?>
Have you tried this:
$data['main_content'] = 'products/single_res_view.php';
If not, can you triple check that the path and file names are correct? Otherwise, can you echo the value of $main_content just in case you're overwriting it somewhere?

Resources