i'm working on zf2 and try to use 2 differents layouts. 1 layout for a public module and another one (private layout") for all the others. Its works pretty well but my zfcuser module in the public module use the other layout :/
i tried this :
'template_map' => array(
'zfc-user/user/login' => __DIR__ . '/../view/layout/blank.phtml', // blank is my public layout
),
Instead of get the form in my layout, i get my form in the public layout AND in the "private" layout ...
Does someone can help me ?
The code evan provides here http://blog.evan.pro/module-specific-layouts-in-zend-framework-2 will do what you need with one minor change, replace __NAMESPACE__ with 'ZfcUser' so that you're listening for ZfcUser controller actions
public function init(ModuleManager $moduleManager)
{
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach('ZfcUser', 'dispatch', function($e) {
// This event will only be fired when an ActionController under the ZfcUser namespace is dispatched.
$controller = $e->getTarget();
$controller->layout('layout/alternativelayout');
}, 100);
}
Added to composer.json
"evandotpro/edp-module-layouts": "1.0"
Created /module/Application/view/layout/blank.phtml
<?php echo $this->content;
Added this to /config/autoload/global.php
return array(
'module_layouts' => array(
'ZfcUser' => 'layout/blank'
));
Finally to /module/Application/config/module.config.php
'view_manager' => array(
'template_map' => array(
//add this line
'layout/blank' => __DIR__ . '/../view/layout/blank.phtml',
Related
I'm working on a project with Fuel. I created a pagination , first page has data truly in it but when I click on other pages , url changes but page never refresh and it doesn't show other pages.
codes:
code in Controller :
$config = array(
'pagination_url' => 'http://localhost/body-app/public/app/list/',
'total_items' => 12,
'per_page' => 3,
'uri_segment' => 5,
// or if you prefer pagination by query string
//'uri_segment' => 'page',
);
$pagination = Pagination::forge('mypagination', $config);
$data['example_data'] = DB::select('*')
->from('bodies')
->limit($pagination->per_page)
->offset($pagination->offset)
->execute()
->as_array();
$data['pagination'] = $pagination;
$view=View::forge('app/list',$data);
and my foreach in View is something like this :
<?php foreach($example_data as $per) {
echo $per['name'] ;
} ?>
and finally code to show pagination :
<?php echo Pagination::instance('mypagination')->render(); ?>
If you work with segment number, you should change the route.php file, and add the example 'prod/page/(:page)?' => 'prod' , or add in the you controller one segment string example 'uri_segment' => 'examplenumberpage'.
I'd like to display custom posts from specific category in Wordpress in custom page.
My code is:
<?php $loop = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
?>
I'd like to display post from "loze" category.
Greetings
You can use category_name for this. Amend your WP_Query as follows:
$loop = new WP_Query(
array(
'post_type' => 'product',
'category_name' => 'loze',
'posts_per_page' => -1
)
);
However, I would recommend using the category ID instead (referenced using cat instead of category_name) as it's future-proofed somewhat (you could change the name of the category).
There is lots of information on this in the category section of the WordPress Codex for WP_Query.
I am rather new to opencart and I'm currently developing a shop where I need to be able to display product attributes inside the cart. I searched allover but apparently no one had the need for this feature.
I short, i tried to duplicate the way attributes are retrieved in the product page but no success.
I modified the controller adding this line:
$this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
I also added:
<?php foreach ($attribute_groups as $attribute_group) { ?>
<?php echo $attribute_group['name']; ?>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<?php echo $attribute['name']; ?>
<?php echo $attribute['text']; ?>
<?php } ?>
<?php } ?>
<?php } ?>
with no succes.
I guess I have to modify somehow system/library/cart.php. The problem is that I am not savvy enough to know how to do it!
At this point I decided to ask for help here!
Any ideas please?
This isn't as hard as it would seem on the surface you'll only need to edit 2 files and open 3.
--1-- Add the method for retrieving attributes to the cart class.
Open catalog/model/catalog/product.php
Find the method getProductAttributes($product_id) and copy the entire method to your clipboard.
Open system/library/cart.php and after the getProducts() method paste your copied method.
--2-- Just above where you pasted the code, at the end of the getProducts() method you'll see where the products array is built for the view, it looks similar to this:
$this->data[$key] = array(
'key' => $key,
'product_id' => $product_query->row['product_id'],
'name' => $product_query->row['name'],
'model' => $product_query->row['model'],
'shipping' => $product_query->row['shipping'],
'image' => $product_query->row['image'],
'option' => $option_data,
'download' => $download_data,
'quantity' => $quantity,
'minimum' => $product_query->row['minimum'],
'subtract' => $product_query->row['subtract'],
'stock' => $stock,
'price' => ($price + $option_price),
'total' => ($price + $option_price) * $quantity,
'reward' => $reward * $quantity,
'points' => ($product_query->row['points'] ? ($product_query->row['points'] + $option_points) * $quantity : 0),
'tax_class_id' => $product_query->row['tax_class_id'],
'weight' => ($product_query->row['weight'] + $option_weight) * $quantity,
'weight_class_id' => $product_query->row['weight_class_id'],
'length' => $product_query->row['length'],
'width' => $product_query->row['width'],
'height' => $product_query->row['height'],
'length_class_id' => $product_query->row['length_class_id']
);
Now simply add a call to that getAttributes method to the array:
'attributes' => $this->getProductAttributes($product_query->row['product_id'])
Now open your cart template: catalog/view/theme/yourtheme/common/cart.tpl and right where the product option loop is, you can now loop through your attributes just like the options.
the code i put in the mytheme template.php
function mytheme_theme(){
return array(
'mytheme_example' => 'example',
'argument' => array('myvar' => null),
);
}
the code i put in the node.tpl.php
<?php
$html = "";
$myvar = "hello,world";
$html .= theme('mytheme_example', myvar);
return $html;
?>
the code i put into the example.tpl.php
<div>
here is the <b><?php print myvar; ?></b>being created.
</div>
i have cleared the cache,but on the node article's page, there is no any output about hello world.
ps:which files i can use the hook_theme, template.php, module file. are there any files i can use this hook?
It looks like you have declared your hook_theme correctly in template.php so I do not think this is the issue.
I did spot a syntax issue with your node.tpl.php, should it not be:
<?php
$vars = array('myvar' => 'hello, world');
$html = theme('mytheme_example', $vars);
return $html;
?>
Note the associate array, with the 'myvar' (the variable declared in hook_theme), is being passed in as the key.
Another point, it is standard practice to name the template file the same as the hook name, so I would suggest calling the template mytheme-example.tpl.php.
See drupal.org for more information
I don't know if you have solved that issue yet.
I would try to declare my theme this way:
function mytheme_theme(){
return array(
'mytheme_example' => array(
'arguments' => array('arguments'=>array()),
'template' => 'example',
),
}
That's how I usually do and it works fine on me.
I have one button and onclick i want javascript function to be called which contains alert message...............in drupal
i tried many things like...........
1)i created button using
$form['click'] = array(
'#type' => 'button',
'#attributes' => array('onclick' =>_____________),//dnt know what to give for onclick
'#value' => t('click'),
);
2)used drupal_add_js(drupal_get_path('module', 'document').'/eg.js', 'module');in hook_form_alter()
3).js file is as follows
function message()
{
alert("Catch ->This alert box was called");
} -->
want alert message to be displayed on button click.
Kindly help................
Thanks in advance
$form['search_something'] = array(
'#type' => 'button',
'#value' => t('Search'),
'#attributes' => array('onclick' => 'searchsomething()),
);
this is the piece of code to call javascript on button click.
Javascript function
function searchsomething(){
alert("hello");
}