I need my data to get passed all the way from my controller -> page (view) -> users (view). How can I pass the data from my controller to the most nested view?
In my controller, I get some data called $users.
In my controller, I load a view called "page".
In my view called "page", I load views called "users".
Here is an example of how I think I can do it. Is this smart or incorrect?
In my controller I can do:
$data['users'] = $array_of_user_objects;
$this->load->view('page', $data);
Then in my page (view) I can do:
<div>
<h1>Im a page!</h1>
<?php $this->load->view('users', $users); ?>
</div>
Then in my users (view) I can do:
<h1>Hi my name is: <?php echo $name; ?></h1>
if you are doing things in controller like
$data['users'] = $array_of_user_objects;
$this->load->view('page', $data);
then in page(view) you can do simply
<div>
<h1>Im a page!</h1>
<?php echo $users->name ?> //if its an object otherwise $users['name']
</div>
and in your users(view)
<h1>Hi my name is: <?php echo $users->name; ?></h1> //if its an object otherwise $users['name']
please let me know if you face any problem.
in controller
$users = $array_of_user_objects;
$data['users'] = $this->load->view('users', $users, true);
$this->load->view('page', $data);
in 'page' view
<div>
<h1>Im a page!</h1>
<?=$users ?>
</div>
you do not need use <?php $this->load->view('users', $users); ?>
but <?php $this->load->view('users'); ?>
and you need a loop in your users view like this
<?php foreach($users as $user): ?>
Hi my name is: <?php echo $user->name; ?>
<?php endforeach;?>
Related
I have added 4 to 5 attributes in manufacture and shown in right column of front end.Now i want to link the each attributes of manufacture. if i will click an attribute of a manufacturer, it will show all the products which contain that arribute/brand.
if anyone knows this, please help me out.
thanks!
I have shown the attribute name in front end by the below code
<?php
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'Manufacturer');
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
if(count( $options)>0){
?>
<div class="title_box">Manufacturers</div>
<?php $i=1;?>
<ul class="left_menu">
<?php
foreach($options as $eachval){
?>
<?php if($i%2==0){ ?>
<li class="even"><?php echo $eachval['label']?></li>
<?php } else { ?>
<li class="odd"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>
<?php } } ?>
I have made one page manu.phtml in catalog/product page and put the following above code now how to give link to that arribute...........please describe briefly
in href link,what i have to write so that when i will click on any attribute it will show all products associated to that attribute/brand.
There is always the option of creating a new module with a custom controller that would list the products from a specified brand, but that is a painful process even if it's the clean way.
Here is a simple version if you don't mind the ugly urls.
The main idea is to link your brand names to the advanced search page with a specific brand filled in.
You can get the url like this:
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'brand='.$value->getId()))
You just need now to get the id of the specific brand ($value->getId()), but if you can get the name you can get the id also.
And don't forget to specify that the brand attribute is used in advanced search. You can do that by editing the attribute in the backend.
[EDIT]
Make your ul element look like this:
<ul class="left_menu">
<?php
foreach($options as $eachval){
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'Manufacturer='.$eachval['value']));
?>
<?php if($i%2==0){ ?>
<li class="even"><?php echo $eachval['label']?></li>
<?php } else { ?>
<li class="odd"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>
Small tip off topic. You can avoid duplication of the li elements in your code like this
<ul class="left_menu">
<?php
foreach($options as $eachval){
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'Manufacturer='.$eachval['value']));
?>
<li class="<?php echo ($i%2 == 0) ? 'even':'odd';?>"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>
i have a right menu in my ci blog site that contains categories and no. of post that is subjected to change, has the following format,
Categories:
Science(24)
education(32)
....
....
the number is brackets is the total amount of post in that category.
my template file is here:
$this->load->view('includes/header');
$this->load->view($main_content);
$this->load->view('includes/footer');
And my right menu is in the footer file.
How could i achieve this?
you better have a main view divided into divs(header, main_content,footer,right_menu) always loaded and load each view in the appropriate div.
<html>
<body>
<div id="header">
<?php $this->load->view('header'); ?>
</div>
<div id="body">
<div id="top_menu">
<?php $this->load->view('top_menu'); ?>
</div>
<div id="main_content">
<?php $this->load->view('main_content'); ?>
</div>
</div>
<div id="footer">
<?php $this->load->view('footer'); ?>
</div>
</body>
</html>
You can also use this system for including header/footer etc:
<?php
/**
* /application/core/MY_Loader.php
*
*/
class MY_Loader extends CI_Loader {
public function template($template_name, $vars = array(), $return = FALSE)
{
$content = $this->view('templates/header', $vars, $return);
$content .= $this->view($template_name, $vars, $return);
$content .= $this->view('templates/footer', $vars, $return);
if ($return)
{
return $content;
}
}
}
Then, in your controller, this is all you have to do:
<?php
$this->load->template('body');
Code if from user: landons
Hi everyone thank you for taking time to look at my question.
I have tried to run view (site_nav, site_header and site_footer) together only and it worked fine.
When I tried to run view (view_home) and the models it also worked fine.
However when I run all the views and models together, the view (site_nav, site_header and site_footer) does not work.
Could anyone please help?
public function home(){
$this->load->model("model_cms_home");
$data["results"] = $this->model_cms_home->getData("cms_home");
$this->load->view("site_nav");
$this->load->view("site_header");
$this->load->view("view_home", $data);
$this->load->view("site_footer");
}
VIEW("view_home")
<div id="home_hat1"> <img src="<?php echo base_url(); ?>pics/home_hat1.jpg"> </div>
<div id="content">
<div id="dinner">
<div class="home_title">
<?php
$query = $this->db->query("SELECT `title` , `text1` FROM `cms_home` WHERE `ID` =1");
if ($query->num_rows() > 0){
$row = $query->row_array();
echo $row['title'];
}
?>
</div>
<div class="home_content">
<?php
$query = $this->db->query("SELECT `title` , `text1` FROM `cms_home` WHERE `ID` =1");
if ($query->num_rows() > 0){
$row = $query->row_array();
echo $row['text1'];
}
?>
</div>
</div>
You cannot call multiple view in one controller function.
This can be done into view.
I suggest you that you should first create a templete and in that template call your views like this
templete.php
<html>
<head>
<body>
$this->load->view("site_nav");
$this->load->view("site_header");
<?php echo $content; ?>
$this->load->view("site_footer");
</body>
</head>
</html>
MY suggestion is to call other page in view_home using include();. You cant see other pages as the last page will be called according to your code. If you put an alert in each page you will know it has actually called all the pages.
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
<div class="box-collateral <?php echo "box-{$alias}"?>">
<?php if ($title = $this->getChildData($alias, 'title')):?>
<h2><span><?php echo $this->escapeHtml($title); ?></span></h2>
<?php endif;?>
<?php echo $html; ?>
</div>
<?php endforeach;?>
<?php echo $this->getChildHtml('product_additional_data') ?>
what's those line meaning in magento?
foreach over each child (that is grouped by name detailed_info with method getchildhtml) and output the data from those blocks
get the html of product_additional_data block
This is the snippet of code from the catalog/product/view.phtml that displays Description, Custom Options, and other detailed product information in the front end view.
Just wondering if anyone has any idea how to show comments on the customers printable order - http://www.mydomain.com/sales/order/print/order_id/48/
I can see the file that I need to edit is “/public_html/app/design/frontend/default/mytemplate/template/sales/order/print.phtml” but am unsure what code I need to add to display the comments.
FYI: We are using this extension to make the order comments box show up on the order page - http://www.magentocommerce.com/magento-connect/catalog/product/view/id/10860/. The order comments are successfully displayed on the order email but we need them be be displayed on the customers order pages as well.
Thanks for your help in advance :)
+1 for code_break, who answered this nicely. Here's my own version for completeness:
$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('status',array('pending','processing'));
foreach ($orders as $order) {
$orderComments = $order->getAllStatusHistory();
foreach ($orderComments as $comment) {
$body = $comment->getData('comment');
if (strpos(strtolower($body),'some text') !== false) {
// do something cool here...
}
}
}
Use as you wish. Hope it helps.
The last post used the getVisibleStatusHistory method of the order object, but the first comment entered on an order is never visible. There are several methods for grabbing the status history and setting it in the order object.
That being said we might want to list all of the comments that are marked as visible on front-ed and the first comment entered when the order is created. I've substitued your formatting with a <p> tag.
<?php $_history = $order->getAllStatusHistory(); ?>
<?php $_buffer = array(); ?>
<?php $_i=1; ?>
<?php foreach ($_history as $_historyItem): ?>
<?php // Ignore the visibility for the first comment ?>
<?php if ( $_historyItem->getData('is_visible_on_front') == 1 || $_i == count($_history) ): ?>
<?php $_buffer[] = $_historyItem->getData('comment'); ?>
<?php endif; ?>
<?php $_i++; ?>
<?php endforeach; ?>
<?php if ( count($_buffer) > 0 ): ?>
<p><?php echo implode( $_buffer, '</p><p>' ); ?></p>
<?php endif ?>
As you are asking especially for the oder comment from MageMaven OrderComment this would be the easiest solution:
<p><?php echo nl2br($_order->getCustomerNote()); ?></p>
Hey try adding this code I havent tested it but i have a feeling it will work for you:
<?php $_history = $_order->getVisibleStatusHistory() ?>
<?php if (count($_history)): ?>
<div class="order-additional order-comments">
<dl class="order-about">
<?php foreach ($_history as $_historyItem): ?>
<dd>
<span class='lowcase'><?php echo $_historyItem->getComment()?></span>
</dd>
<?php endforeach; ?>
</dl>
</div>
<?php endif?>