i make index action in which i want to get data of calender and show this data using index.phtml but always no calendar shown,how i show calendar data?
here is my indexaction:
public function indexAction()
{
$dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
$qb = $dm->createQueryBuilder('Calendar\Document\Calendar')->select('title', 'description');
$query = $qb->getQuery();
$calendars = $query->execute();
return array('calendars' => $calendars);
}
and here is my index.phtml:
<?php
$calendars = $this->calendars;
$title = 'Calendars by '.$this->escapeHtml($calendars[0]->email);
$this->headTitle($title);
?>
<h3><?php echo $this->escapeHtml($title); ?></h3>
<ul>
<li>Create New Calendar</li>
</ul>
<h4>Calendars created by you</h4>
<?php if (is_null($calendars)): ?>
<p>No calendars</p>
<?php else: ?>
<table class="table">
<tr>
<th>calendar name</th>
<th>description</th>
<th>owner</th>
<th>actions</th>
</tr>
<?php foreach ($calendars as $calendar) : ?>
<tr>
<td>
<a href="<?php echo $this->url('calendar',array('action'=>'show', 'id' => $calendar->calendar_id));?>">
<?php echo $this->escapeHtml($calendar->title);?>
</a>
</td>
<td><?php echo $this->escapeHtml($calendar->description);?></td>
<td>
<?php echo $this->gravatar($this->escapeHtml($calendar->email));?>
<?php echo $this->escapeHtml($calendar->email);?>
</td>
<td>
<a href="<?php echo $this->url('calendar',
array('action'=>'settings', 'id' => $calendar->calendar_id));?>">Settings</a>
<a href="<?php echo $this->url('calendar',
array('action'=>'delete', 'id' => $calendar->calendar_id));?>">delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
and here is my response:
Doctrine\ODM\MongoDB\Cursor Object
(
[baseCursor:Doctrine\ODM\MongoDB\Cursor:private] => Doctrine\MongoDB\Cursor Object
(
[connection:protected] => Doctrine\MongoDB\Connection Object
(
[mongo:protected] => MongoClient Object
(
[connected] => 1
[status] =>
[server:protected] =>
[persistent:protected] =>
)
[server:protected] => mongodb://127.0.0.1:27017/events
[options:protected] => Array
(
)
[config:protected] => Doctrine\ODM\MongoDB\Configuration Object
(
[attributes:protected] => Array
(
[mongoCmd] => $
[retryConnect] => 0
[retryQuery] => 0
[autoGenerateProxyClasses] => 1
[proxyDir] => data/DoctrineMongoODMModule/Proxy
[proxyNamespace] => DoctrineMongoODMModule\Proxy
[autoGenerateHydratorClasses] => 1
[hydratorDir] => data/DoctrineMongoODMModule/Hydrator
[hydratorNamespace] => DoctrineMongoODMModule\Hydrator
[defaultDB] => events
[metadataCacheImpl] => Doctrine\Common\Cache\ArrayCache Object
(
[data:Doctrine\Common\Cache\ArrayCache:private] => Array
how i show data on index page?
You need a view model to render your data. Instead of
return array('calendars' => $calendars);
You want this for a View:
$viewModel = new ViewModel
(
array
(
'calendars' => $calendars,
)
);
return $viewModel;
or this for Json:
$jsonModel = new JsonModel
(
array
(
'calendars' => $calendars,
)
);
return $jsonModel;
make sure to add the use statements for your controller:
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
If you want to specify a specific view you can use:
$viewModel->setTemplate('path/to/specific/view.phtml');
or
$viewModel->setTemplate('mapping/for/specifc/view');
with the mapping specified in your module config
Related
Good day. I'm now trying to create detail that come from my sql table.
Here is My PHP:-
public function export()
{
$query = $this->input->cookie("cookie_invent_query");
$data['header'] = $this->modelmodel->showdata($query);
foreach($data['header'] as $header){
$data['detail'][] = $this->modelmodel->showdata("select * from DeliveryOrderDetail
where deliveryordertransno = '".$header->TransactionNo."' ");
}
echo "<pre>"; print_r($data['detail']);
$this->load->view("do_mutasi/export",$data);
}
with my script above i get tis in print_r()
result from $data['header']
Array
(
[0] => stdClass Object
(
[FinalReleaseStatus] => 1
[DeliveryOrderDate] => 2016-12-21 17:25:18.487
[TransactionNo] => DO-DL-K-LFKG-11
[DocumentNo] => DOZZ-DL-K-LFKG-6
[ToCustomerCode] => AFF004
[CategoryCode] => ZZ
[ETADate] => 2016-12-21 17:25:18.487
)
)
result from $data['detail']
Array
(
[0] => Array
(
[0] => stdClass Object
(
[TransactionNo] => DOD-DL-K-LFKG-9
[LineNo] => 1000
[ItemCode] => FA00000111
[DeliveryOrderTransNo] => DO-DL-K-LFKG-11
[ExtraRemark] => 0
[ExtraRemark2] => 0
[Quantity] => 3.00000000000000000000
[UOMCode] => PCS
[CreatedDate] => 2016-12-21 17:26:25.063
[CreatedBy] => boby
[ModifiedDate] => 2016-12-21 17:26:25.063
[ModifiedBy] =>
)
)
)
then after i send it to my view and this what i can do for now
<?php foreach($header as $hdr) { ?>
Header
<table class="table">
<thead>
<tr>
<th>Trnsaction No</th>
<th>Document No</th>
<th>To Customer</th>
<th>Delivery Order Date</th>
</tr>
</thead>
<tbody>
<td><?=$hdr->TransactionNo;?></td>
<td><?=$hdr->DocumentNo;?></td>
<td><?=$hdr->ToCustomerCode;?></td>
<td><?=$hdr->DeliveryOrderDate;?></td>
</tbody>
</table>
Detail
<table>
<thead>
<tr>
<th>Transaction No</th>
<th>Item Code</th>
<th>Quntity</th>
<th>Uom Code</th>
</tr>
</thead>
<tbody>
<?php
foreach($detail as $rsltdt =>$key) { ?>
<tr>
<td><?=$rsltdt['TransactionNo'];?></td>
<td><?=$rsltdt['ItemCode'];?></td>
<td><?=$rsltdt['Quantity'];?></td>
<td><?=$rsltdt['UOMCode'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
Asyou can see. I loop the detail inside the header loop. Because in some records there are multiple detail. I loop the header because i want to show it multiple records not just one record
here is the result so far
I can't show detail. So my question is. How can i show the detail depends on header.
[TransactionNo] = [DeliveryOrderTransNo]
Check once:-
foreach($detail as $rsltdt) {
foreach ($rsltdt as $rsl){ ?>
<tr>
<td><?=$rsl->TransactionNo;?></td>
<td><?=$rsl->ItemCode;?></td>
<td><?=$rsl->Quantity;?></td>
<td><?=$rsl->UOMCode;?></td>
</tr>
<?php } } ?>
It is better to put all details in its corresponding header :
public function export()
{
$query = $this->input->cookie("cookie_invent_query");
$data['header'] = $this->modelmodel->showdata($query);
foreach($data['header'] as $header){
$data['header']['details'] = $this->modelmodel->showdata("select * from DeliveryOrderDetail
where deliveryordertransno = '".$header->TransactionNo."' ");
}
}
then you can simply write the second loop :
foreach($hdr['details'] as $rsltdt) { ?>
<tr>
<td><?=$rsltdt->TransactionNo;?></td>
<td><?=$rsltdt->ItemCode;?></td>
<td><?=$rsltdt->Quantity;?></td>
<td><?=$rsltdt->UOMCode;?></td>
</tr>
<?php } ?>
You don't need to nest the details array anymore :
put:
$data['header']['details'] = $this->modelmodel->showdata("select * f....
instead of:
$data['header']['details'][] = $this->modelmodel->showdata("select * f....
I tried render data in loop and if extend_tag field have same text group in one container.
I only know hard code like below, loop data base on how many known extend_tag group, but actually the extend_tag numbers is unknown might be tag_ and any digit , any idea how to solve it?
data
[tag] => Array (
[0] => Array (
[id] => 1
[extend_tag] => tag_0
)
[1] => Array (
[id] => 2
[extend_tag] => tag_11
)
[2] => Array (
[id] => 3
[extend_tag] => tag_4
)
)
<ul class="container">
<?php foreach($rows['tag'] as $eachRowsTag) { ?>
<?php if ($eachRowsTag['extend_tag'] == 'tag_0') { ?>
<li>><?php echo $eachRowsTag['id']; ?></li>
<?php } ?>
<?php } ?>
</ul>
<ul class="container">
<?php foreach($rows['tag'] as $eachRowsTag) { ?>
<?php if ($eachRowsTag['extend_tag'] == 'tag_1') { ?>
<li>><?php echo $eachRowsTag['id']; ?></li>
<?php } ?>
<?php } ?>
</ul>
...
Why not group them first, then iterate over the resulting array. Something like the following.
foreach ($tags as $tag) {
$grouped[$tag['extend_tag']][] = $tag;
}
// Now $grouped is something along the lines of:
// [
// 'tag_0' => [
// [ 'id' => 1, 'extend_tag' => 'tag_0'],
// ..
// ],
// ..
// ]
foreach($grouped as $extend_tag => $tags) {
echo "All tags in $extended_tag.";
foreach($tags as $tag) {
echo $tag['id'];
}
}
// For something like:
// All tags in tag_0.
// 1
// 4
// All tags in tag_1.
// ..
I Have an array called $pages content is as follows:
Array
(
[01-about-us] => Page Object
(
[_uri] => about-us
[_menuItem] => 01
[_visable] => 1
)
[02-contact] => Page Object
(
[_uri] => contact
[_menuItem] => 02
[_visable] => 1
)
[_sitemap] => Page Object
(
[_uri] => sitemap
[_menuItem] =>
[_visable] =>
)
[home] => Page Object
(
[_uri] => home
[_menuItem] =>
[_visable] => 1
)
)
is there an easy way to loop through and get page objects by there properties ie:
<?php foreach($pages->_visible() AS $p): ?>
<li> page </li>
<?php endforeach ?>
No. You will have to use an if:
foreach ($pages as $page) {
if ($page->_visible == 1) {
echo "<li>page</li>";
}
}
(Note also you misspelt visible in the array, perhaps a typo?)
Or you can utilize PHP's array_filter function:
$pagesVisible = array_filter($pages, function($page) {
return (bool) $page->_visible;
});
foreach ($pagesVisible as $key => $page) {
print '<li>' . $key . '</li>';
}
Or shorthand it to:
$filter = function($page) {
return (bool) $page->_visible;
};
foreach (array_filter($pages, $filter) as $key => $page) {
print '<li>' . $key . '</li>';
}
You just need to loop through the pages array and inside the loop access the object properties like:
<?php foreach($pages as $k => $p): ?>
<?php if ($p->_visable === 1): ?>
<li><?php echo $k; ?></li>
<?php endif; ?>
<?php endforeach; ?>
Please note that visable is misspelled but thats how it is in your question
I have a simplepie feed that spits out multiple feeds from each of the URL's that are loaded into a a associative array.
This associative array is used to sort the arrays alphabetically using the values.
I'm trying to use that same value sort and keep all of the arrays with the same URL or value together so that when the foreach loop runs I get one div per URL containning all the feeds from that URL for the day
<?php
require_once('php/autoloader.php');
$feed = new SimplePie(); // Create a new instance of SimplePie
// Load the feeds
$urls = array(
'http://abcfamily.go.com/service/feed?id=774372' => 'abc',
'http://animal.discovery.com/news/news.rss' => 'animalplanet',
'http://www.insideaolvideo.com/rss.xml' => 'aolvideo',
'http://feeds.bbci.co.uk/news/world/rss.xml' => 'bbcwn',
'http://www.bing.com' => 'bing',
'http://www.bravotv.com' => 'bravo',
'http://www.cartoonnetwork.com' => 'cartoonnetwork',
'http://feeds.cbsnews.com/CBSNewsMain?format=xml' => 'cbsnews',
'http://www.clicker.com/' => 'clicker',
'http://feeds.feedburner.com/cnet/NnTv?tag=contentBody.1' => 'cnet',
'http://www.comedycentral.com/' => 'comedycentral',
'http://www.crackle.com/' => 'crackle',
'http://www.cwtv.com/feed/episodes/xml' => 'cw',
'http://disney.go.com/disneyxd/' => 'disneyxd',
'http://www.engadget.com/rss.xml' => 'engadget',
'http://syndication.eonline.com/syndication/feeds/rssfeeds/video/index.xml' => 'eonline',
'http://sports.espn.go.com/espn/rss/news' => 'espn',
'http://facebook.com' => 'facebook',
'http://flickr.com/espn/rss/news' => 'flickr',
'http://www.fxnetworks.com//home/tonight_rss.php' => 'fxnetworks',
'http://www.hgtv.com/' => 'hgtv',
'http://www.history.com/this-day-in-history/rss' => 'history',
'http://rss.hulu.com/HuluRecentlyAddedVideos?format=xml' => 'hulu',
'http://rss.imdb.com/daily/born/' => 'imdb',
'http://www.metacafe.com/' => 'metacafe',
'http://feeds.feedburner.com/Monkeyseecom-NewestVideos?format=xml' => 'monkeysee',
'http://pheedo.msnbc.msn.com/id/18424824/device/rss/' => 'msnbc',
'http://www.nationalgeographic.com/' => 'nationalgeographic',
'http://dvd.netflix.com/NewReleasesRSS' => 'netflix',
'http://feeds.nytimes.com/nyt/rss/HomePage' => 'newyorktimes',
'http://www.nick.com/' => 'nickelodeon',
'http://www.nickjr.com/' => 'nickjr',
'http://www.pandora.com/' => 'pandora',
'http://www.pbskids.com/' => 'pbskids',
'http://www.photobucket.com/' => 'photobucket',
'http://feeds.reuters.com/Reuters/worldNews' => 'reuters',
'http://www.revision3.com/' => 'revision3',
'http://www.tbs.com/' => 'tbs',
'http://www.theverge.com/rss/index.xml' => 'theverge',
'http://www.tntdrama.com/' => 'tnt',
'http://www.tvland.com/' => 'tvland',
'http://www.vimeo.com/' => 'vimeo',
'http://www.vudu.com/' => 'vudu',
'http://feeds.wired.com/wired/index?format=xml' => 'wired',
'http://www.xfinitytv.com/' => 'xfinitytv',
'http://www.youtube.com/topic/4qRk91tndwg/most-popular#feed' => 'youtube',
);
$feed->set_feed_url(array_keys($urls));
$feed->enable_cache(true);
$feed->set_cache_location('cache');
$feed->set_cache_duration(1800); // Set the cache time
$feed->set_item_limit(0);
$success = $feed->init(); // Initialize SimplePie
$feed->handle_content_type(); // Take care of the character encoding
?>
<?php require_once("inc/connection.php"); ?>
<?php require_once("inc/functions.php"); ?>
<?php include("inc/header.php"); ?>
<?php
// Sort it
$feed_items = array();
$items = $feed->get_items();
$urls = array_unique($urls);
foreach ($urls as $url => $image) {
$unset = array();
$feed_items[$url] = array();
foreach ($items as $i => $item) {
if ($item->get_feed()->feed_url == $url) {
$feed_items[$url][] = $item;
$unset[] = $i;
}
}
foreach ($unset as $i) {
unset($items[$i]);
}
}
foreach ($feed_items as $feed_url => $items) {
if (empty($items)) {
?>
<div class="item"><img src="images/boreds/<?php echo $urls[$feed_url] ?>.png"/><p>Visit <?php echo $urls[$feed_url] ?> now!</p></div>
<?
continue;
}
$first_item = $items[0];
$feed = $first_item->get_feed();
?>
<?php
$feedCount = 0;
foreach ($items as $item ) {
$feedCount++;
?>
<div class="item"><strong id="amount"><?php echo $feedCount; ?></strong><img src="images/boreds/<?php echo $urls[$feed_url] ?>.png"/><p><?php echo $item->get_title(); ?></p></div>
<?php
}
}
?>
<?php require("inc/footer.php"); ?>
Maybe you can use this one:
$feed = new SimplePie();
$feed->set_feed_url('http://myfirstfeed','http://mysecondfeed');
foreach( $feed->get_items() as $k => $item ) {
echo "<div id='".$k.'">";
echo $item->get_permalink();
echo $title = $item->get_title();
echo $item->get_date('j M Y, g:i a');
echo $item->get_content();
echo "</div>";
}
The controller:
$params = array(
'fields' => array('Course.id', 'Course.weekstart'),
'conditions' => array(
'Course.program_id' => $program_id
)
);
$paramsflagged = array(
'conditions' => array(
'Course.course_full' => 1,
'Course.program_id' => $program_id
),
'fields' => array('Course.id', 'Course.weekstart')
);
$flaggedcourses = $this->Course->find('list', $paramsflagged);
$courses = $this->Course->find('list', $params);
$this->set('courses', $courses);
$this->set('flaggedcourses', $flaggedcourses);
The view generating the select list for all options (using the array courses):
<select>
<?php foreach ($courses as $key => $course): ?>
<option id="<?php echo $key;?>">
<?php echo $course; ?>
</option>
<?php endforeach;?>
</select>
Courses array=>
Array
(
[2836] => 4 16:40:00
[2835] => 3 13:20:00
)
FlaggedCourses array=>
Array
(
[2835] => 3 13:20:00
)
So what would be the best way to create a new array of select options in that view which can 'add a class' to options that were in the flaggedcourses array?
use a multidimensional array
Array
(
[2836] => array('value'=> '4 16:40:00', 'flagged' => '')
[2835] => array('value'=> '3 13:20:00', 'flagged' => 'selected')
)
<select>
<?php foreach ($courses as $key => $course): ?>
<option id="'.$key.'" selected="'.$course['flagged'].'">
<?php echo $course['value']; ?>
</option>
<?php endforeach;?>
</select>
<select>
<?php foreach ($courses as $key=>$course): ?>
<?php
if (array_key_exists($key, $flaggedcourses)) {
$class = ' class="flagged"';
} else {
$class = '';
}
?>
<option id="<?= $key;?>"<?= $class; ?>>
<?php echo $course; ?>
</option>
<?php endforeach;?>
</select>
Try this
foreach ($courses as $key=>$course):
if (isset($flaggedcourses[$key])):
$color = ' style="color:red"';
else:
$color = '';
endif;
echo <<<option
<option id="{$key}"{$color}>{$course}</option>
option;
endforeach;