Guest PsychoBT Posted October 19, 2011 Share Posted October 19, 2011 I'm trying to build a very simple newsbox. I've managed to fix the admin section for insertion into the database. But I have problems with getting data on the website. I have simply copied an existing box (siteDocs.inc.php & siteDocs.tpl) and has tried to change it for my needs. But I don't get it to work! Here's my code: index.inc.php require_once'includes'.CC_DS.'boxes'.CC_DS.'news.inc.php'; $body->assign('NEWS',$box_content); news.inc.php <?php if (! defined('CC_INI_SET')) die("Access Denied"); ## query database $cache = new cache('boxes.news.master'); $results = $cache->readCache(); if (! $cache->cacheStatus) { $results = $db->select("SELECT nyhet, datum FROM " . $glob['dbprefix'] . "CubeCart_news ORDER BY datum ASC"); $cache->writeCache($results); } $box_content = new XTemplate('boxes' . CC_DS . 'news.tpl'); ## Build attributes if ($results) { foreach ($results as $i => $result) { $result['nyhet'] = validHTML($result['nyhet']); $box_content->assign('NYHET', $result); $box_content->parse('news.a'); } } $box_content->parse('news'); $box_content = $box_content->text('news'); ?> news.tpl <!-- boxes/news.tpl --> <!-- BEGIN: news --> <ul> <li>{NYHET}</li> </ul> <!-- END: news --> Quote Link to comment Share on other sites More sharing options...
bsmither Posted October 19, 2011 Share Posted October 19, 2011 Welcome PsychoBT! Glad to see you made it to the forums. A couple of things I see... 1. In news.tpl, you have a news block, but no nested a block. Presumably the a block would actually contain the list item tag. So, surround the list item tags with <!-- BEGIN: a --> and <!-- END: a -->. 2. In news.inc.php, the foreach statement is using the $results array to extract a key/value pair per iteration. The variable $i is not defined anywhere. Perhaps you mean to cycle through the array without regard to the actual key. If that's the case, then use foreach($results as $result){. 3. But then, it seems that each element of the array $results is another array ($result), for which you are working on the value specified by the key 'nyhet'. Afterwards, you are assigning the $result array to the scalar placeholder {NYHET}. If you want to assign an array to a placeholder, the placeholder must be expressed as {NYHET.nyhet} and {NYHET.skribent}. And this might not work. Consider using NYHETER as the placeholder's group name. Quote Link to comment Share on other sites More sharing options...
Guest PsychoBT Posted October 19, 2011 Share Posted October 19, 2011 IT WORKS! THANK YOU SO MUCH!!!! Quote Link to comment Share on other sites More sharing options...
Guest PsychoBT Posted October 19, 2011 Share Posted October 19, 2011 Only a little problem; It only shows the first post... When I add another newspost it doesn't show. Any help on that? ;) Quote Link to comment Share on other sites More sharing options...
bsmither Posted October 19, 2011 Share Posted October 19, 2011 I'm not exactly sure how CC4's cache works, so I can't say if having added new records to a table will trigger the cache to dump what it has. Maybe by looking at another admin screen, you can learn if there is a standard statement that dumps the cache when the screen adds/edits a record. In the meantime, try doing the Clear Cache command from the admin database maintenance screen. This supposes that the cache has the results from the first successful query (only one record) and the code will use that. Quote Link to comment Share on other sites More sharing options...
leeofaccy Posted October 19, 2011 Share Posted October 19, 2011 Try this for your news.inc.php <?php if (! defined('CC_INI_SET')) die("Access Denied"); ## query database $cache = new cache('boxes.news'); $results = $cache->readCache(); if (! $cache->cacheStatus) { $results = $db->select("SELECT nyhet, datum FROM " . $glob['dbprefix'] . "CubeCart_news ORDER BY datum ASC"); $cache->writeCache($results); } $box_content = new XTemplate('boxes' . CC_DS . 'news.tpl'); ## Build attributes if ($results) { foreach ($results as $result) { $result['nyhet'] = validHTML($result['nyhet']); $box_content->assign('NYHET', $result); $box_content->parse('news.li'); } } $box_content->parse('news'); $box_content = $box_content->text('news'); ?> And this on your news.tpl file <!-- BEGIN: news --> <ul> <!-- BEGIN: li --> <li>{NYHET.nyhet}</li> <!-- END: li --> </ul> <!-- END: news --> Lee Quote Link to comment Share on other sites More sharing options...
Guest PsychoBT Posted October 19, 2011 Share Posted October 19, 2011 That worked, thank you very much Lee! And thanks again bsmither, it helped clearing the cache after changing Lee's changes. Now I just have to figure out how I automatically clean the cache when I add or remove a post. Any idea? :) Quote Link to comment Share on other sites More sharing options...
Guest PsychoBT Posted October 19, 2011 Share Posted October 19, 2011 I added $cache = new cache(); $cache->clearCache(); if (file_exists(CC_ROOT_DIR.CC_DS.'includes'.CC_DS.'extra'.CC_DS.'admin_cat_cache.txt')) { unlink(CC_ROOT_DIR.CC_DS.'includes'.CC_DS.'extra'.CC_DS.'admin_cat_cache.txt'); } in my admin-news-adding-page and i worked Thanks allot guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.