I'm having trouble understanding how to place grocery_CRUD into a view.
My function in my control looks like this:
function folio()
{
$crud = new grocery_CRUD();
$crud->set_table('rfid');
$crud->columns('rfid','timestamp');
$data['output'] = $crud->render();
$data['title'] = 'Control Escolar - Folio';
$this->db->where('id', $this->uri->segment(3));
$data['query'] = $this->db->get('alumnos');
$this->load->view('folio_view', $data);
}
The code in my view file looks like this.
<?php foreach($query->result() as $row) { ?>
Datos Vitales - <B>Status:</b> <?=$row->status?><hr>
<B>Nombre:</b> <?=$row->nombre?> <B>Fecha de Nac:</B> <?=$row->fecha_nac?></br>
<B>Edad:</b> <?=$row->edad?> <B>Sexo:</B> <?=$row->sexo?> <B>Lugar de Nac:</B> <?=$row->lugar_nac?>
<B>Nacionalidad:</B> <?=$row->nacionalidad?><br><br>
Datos Escolar<hr>
<B>Folio:</b> <?=$row->folio?> <B>Grado:</b> <?=$row->grado?> <B>Grupo:</b> <?=$row->grupo?> <B>Turno:</b> <?=$row->turno?> <B>RFID:</b> <?=$row->rfid?><br><br>
Datos Generales<hr>
<B>Domicilio:</b> <?=$row->domicilio?> <B>Colonia:</b> <?=$row->colonia?> <B>Codigo Postal:</b> <?=$row->cpostal?></br>
<B>Telefono Particular:</b> <?=$row->telepart?> <B>Municipio:</b> <?=$row->municipio?></br>
<B>Telefono de Emergencia:</b> <?=$row->tele_emer?> <B>Tutor:</b> <?=$row->tutor?><br><br>
Datos Medicos<hr>
<B>Tipo de Sangre:</b> <?=$row->tipo_de_sangre?></br>
<B>Condiciones Conocidas:</b> <?=$row->condiciones?></br></br>
<hr>
<B>Entradas/Salidas Registradas:</b>
<?php echo $output; ?>
<?php } ?>
Which works well, however when I run it I get this where the CRUD should appear:
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: views/folio_view.php
Line Number: 65
What I'm trying to actually accomplish is for the CRUD to show the only the RFID entries matching the RFID field matching the student.
Actually the error describes exactly what is wrong there. So the problem is that you try to echo an object.
So imagine that your $output is an object like this:
stdClass Object
(
[output] => Your output will appear here....
[js_files] => Array
(
...
)
[css_files] => Array
(
...
)
)
So the solution to your problem is simply this:
echo $output->output;
Also consider that the only thing that grocery CRUD requires is to show somewhere the js_files and the css_files , so don't forget to have this in your template or view:
<?php foreach($output->css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($output->js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
If you want to be more "readable" to you can simply do this:
$data['gcrud'] = $crud->render();
And in your view/template to have something like this:
<?php foreach($gcrud->css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($gcrud->js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
...
<?php echo $gcrud->output; ?>
Lastly but not least, consider that the thing that you are trying to do will not work in the first place as I understood you want multiple CRUDs in one page:
<?php foreach($query->result() as $row) { ?>
...
<B>Entradas/Salidas Registradas:</b>
<?php echo $output->output; ?>
<?php } ?>
However you will realize that for the time being it will not work well for you as grocery CRUD doesn't support multiple CRUD forms in one page for the moment. So if you actually want to use grocery CRUD you have to change the logic that the view will show it
Related
Well we are not able to get the products to display in the product sitemap which is by default available in magento at (http://sitename.com/catalog/seo_sitemap/product/).
We have the following code present in the app/design/frontendbase/default/template/catalog/seo/sitemap.phtml
<?php
/**
* #see Mage_Catalog_Block_Seo_Sitemap_
*/
?>
<?php $_items = $this->getCollection(); ?>
<? //var_dump($_items);?>
<?php if($_items->getSize()): ?>
<ul class="sitemap">
<?php foreach ($_items as $_item): ?>
<li><?php echo $this->escapeHtml($_item->name) ?></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p class="note-msg">
<?php echo $this->__('There are no %s available.', $this->getItemsTitle()); ?>
</p>
<script type="text/javascript">
//<![CDATA[
if ($('sitemap_top_links') != undefined) {
$('sitemap_top_links').hide();
}
//]]>
</script>
<?php endif ?>
We tried to var_dump($_items) the product sitemap page and we were able to get the data dump of product however $_items->getSize() returns 0 and the foreach is not able to parse the $_items array.
Is there a magento backend setting or a product attribute that controls the sitemap behavior. Also the category sitemap seems to be working fine so the issue is specific to products.
I'm using the AheadWorks blog extension for Magento, and my blog pages are working fine. But I want excerpts of my latest posts from certain categories to appear on my home page. I've successfully setup everything thus far by adding:
<block type="blog/blog" name="blog.latest" template="aw_blog/blog-home.phtml" />
to "layout.xml", by adding:
<?php echo $this->getChildHtml('blog.latest') ?>
to my home page's phtml file, and by creating "template/aw_blog/blog-home.phtml".
The problem is that I can't figure out how to limit what categories are shown. For example, you'll see in my "blog-home.phtml" file below that I'm trying to limit the posts to the "news" category. I've tried lots of solutions from other forums, but no matter what I do, I see posts from every category. Does anyone know what I need to add/take away from my code to limit the categories?
<?php $posts = $this->getPosts("news"); ?>
<div id="messages_product_view">
<?php Mage::app()->getLayout()->getMessagesBlock()->setMessages(Mage::getSingleton('customer/session')->getMessages(true)); ?>
<?php echo Mage::app()->getLayout()->getMessagesBlock()->getGroupedHtml(); ?>
</div>
<?php $numberOfPosts = 1 ?>
<?php $renderedPosts = 0 ?>
<?php foreach ($posts as $post): ?>
<div class="postWrapper">
<div class="postTitle">
<h2><a href="<?php echo $post->getAddress(); ?>" ><?php echo $post->getTitle(); ?></a></h2>
</div>
<div class="postContent"><?php echo $post->getPostContent(); ?></div>
<?php echo $this->getBookmarkHtml($post) ?>
<div class="tags"><?php echo $this->getTagsHtml($post) ?></div>
<div class="postDetails">
<?php if ($this->getCommentsEnabled()): ?>
<?php echo $post->getCommentCount(); ?> <a href="<?php echo $post->getAddress(); ?>#commentBox" >Comments</a> |
<?php endif; ?>
<?php $postCats = $post->getCats(); ?>
<?php echo "<h1>" . $postCats[2] . "</h1>"; ?>
<?php if (!empty($postCats)): ?>
<?php echo Mage::helper('blog')->__('Posted in'); ?>
<?php foreach ($postCats as $data): ?>
<?php echo $data['title']; ?>
<?php endforeach; ?>
<?php else: ?>
<?php endif; ?></div>
<?php $renderedPosts ++ ?>
<?php if ($renderedPosts = $numberOfPosts) {
break;
}
?>
</div>
<?php endforeach; ?>
<?php //$this->getPages(); ?>
Following is the quick solution:
Go to aw_blog frontend template, default might be this app/design/frontend/base/default/template/aw_blog/menu.phtml
check and replace:
if ($posts = $this->getRecent():
with
$currentBlogCat = Mage::getSingleton('blog/cat');
if ($posts = $this->getRecent($currentBlogCat['cat_id'])):
Now open up /app/code/community/AW/Blog/Block/Menu/Sidebar.php
check for the below function:
public function getRecent()
add a parameters to it:
public function getRecent($currentCat=false)
Also, replace the following code block
$collection = clone self::$_collection;
if (array_key_exists('categories',$data = $this->getData();) && count(explode(',', $data['categories'])) == 1) {
with
$collection = clone self::$_collection;
$data = $this->getData();
if($currentCat>0)$data['categories']=$currentCat;
# Category fix #
if (array_key_exists('categories',$data ) && count(explode(',', $data['categories'])) == 1) {
Thanks!
I would like to change the leading articles html structure for the blog category page in Joomla 2.5.
It has to be like this
<dl>
<dt>intro-image</dt>
<dd>
<h3>article-title</h3>
<var>published-date</var>
intro-text
</dd>
</dl>
I copied blog.php file into my-template/html/com-content/category/ and modified it
<?php if (!empty($this->lead_items)) : ?>
<?php foreach ($this->lead_items as &$item) : ?>
<dl>
<dt></dt>
<dd>
<?php
$this->item = &$item;
echo $this->item->introtext;
?>
</dd>
<?php
$leadingcount++;
?>
</dl>
<?php endforeach; ?>
But as you see I only managed to show the intro text. How can intro image, article title and published date be displayed on their places? Are there more files, which have to be modified?
I appreciate any help. Thank you.
Half way there. Here is the code but I'm not sure what you mean by the intro image. Is it part of the article? Please explain and I might be able to get it working fully:
<?php foreach ($this->lead_items as &$item) : ?>
<dl>
<dt>
<?php
$params = JComponentHelper::getParams( 'com_content' );
$this->item = &$item;
$images = json_decode($item->images);
if (isset($images->image_intro) and !empty($images->image_intro)) {
$imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro;
$class = (htmlspecialchars($imgfloat) != 'none') ? ' class="size-auto align-'.htmlspecialchars($imgfloat).'"' : ' class="size-auto"';
$title = ($images->image_intro_caption) ? ' title="'.htmlspecialchars($images->image_intro_caption).'"' : '';
echo '<img'.$class.$title.' src="'.htmlspecialchars($images->image_intro).'" alt="'.htmlspecialchars($images->image_intro_alt).'" />';
}
?>
</dt>
<dd>
<h3><?php echo $this->item->title; ?></h3>
<var><?php echo $this->item->publish_up; ?></var>
<?php echo $this->item->introtext; ?>
</dd>
<?php $leadingcount++; ?>
</dl>
<?php endforeach; ?>
<?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?>