7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Latest albums on frontpage
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1055 Views |
-
Latest albums on frontpage

10 August 2010 at 1:04am Last edited: 10 August 2010 1:04am
Hello,
I have setup two main galleries and I was trying to return the five latest albums from both galleries to show in frontpage. This is what I put in my frontpage.php
function LatestAlbums($num=5) {
$albums = DataObject::get_one("ImageGalleryPage");
return ($albums) ? DataObject::get("ImageGalleryAlbum", "ParentID = $albums->ID", "Date DESC", "", $num) : false;
}and in the frontpage.ss :
<ul id="ActivityList">
<% control LatestAlbums %>
<li>
<div class="albumThumbnail">$FormattedCoverImage.SetWidth(75)</div>
<div class="albumInfo">
<h4><a href="$Link" title="$AlbumName">$AlbumName</a></h4>
<p>$Description.FirstParagraph</p>
</div>
</li>
<% end_control %>
</ul>it shows this error :
There has been an error
The website server has not been able to respond to your request.can someone explain what's wrong with this? thanks
-
Re: Latest albums on frontpage

10 August 2010 at 4:48am
Get your site into dev mode so we can see the error!
-
Re: Latest albums on frontpage

10 August 2010 at 4:59am
I get this error:
[User Warning] Cookie 'PastMember' can't be set. The site started outputting was content at line 32 in /home/espace/public_html/mysite/code/ArticlePage.php
GET /?flush=1Line 33 in /home/espace/public_html/sapphire/core/Cookie.php
Source24 $path = ($path) ? $path : Director::baseURL();
25
26 // Versions of PHP prior to 5.2 do not support the $httpOnly value
27 if(version_compare(phpversion(), 5.2, '<')) {
28 setcookie($name, $value, $expiry, $path, $domain, $secure);
29 } else {
30 setcookie($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
31 }
32 } else {
33 if(self::$report_errors) user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
34 }
35 }
36
37 /**
38 * Get a cookie variable
39 */Trace
* Cookie 'PastMember' can't be set. The site started outputting was content at line 32 in /home/espace/public_html/mysite/code/ArticlePage.php
Line 33 of Cookie.php
* Cookie::set(PastMember,1,90,,,,1)
Line 84 of Controller.php
* Controller->init()
Line 32 of ModelAsController.php
* ModelAsController->init()
Line 47 of ModelAsController.php
* ModelAsController->handleRequest(SS_HTTPRequest)
Line 111 of RootURLController.php
* RootURLController->handleRequest(SS_HTTPRequest)
Line 281 of Director.php
* Director::handleRequest(SS_HTTPRequest,Session)
Line 124 of Director.php
* Director::direct(/)
Line 127 of main.php -
Re: Latest albums on frontpage

10 August 2010 at 5:06am Last edited: 10 August 2010 5:07am
Tu as d'éspace blanche quelque place.. Fait certain que tu n'as pas fermé de tags PHP!
-
Re: Latest albums on frontpage

10 August 2010 at 5:23am
thanks, I removed spaces and now it shows this error :
[User Error] Couldn't run query: SELECT "ImageGalleryAlbum"."ClassName", "ImageGalleryAlbum"."Created", "ImageGalleryAlbum"."LastEdited", "ImageGalleryAlbum"."AlbumName", "ImageGalleryAlbum"."Description", "ImageGalleryAlbum"."SortOrder", "ImageGalleryAlbum"."CoverImageID", "ImageGalleryAlbum"."ImageGalleryPageID", "ImageGalleryAlbum"."FolderID", "ImageGalleryAlbum"."ID", CASE WHEN "ImageGalleryAlbum"."ClassName" IS NOT NULL THEN "ImageGalleryAlbum"."ClassName" ELSE 'ImageGalleryAlbum' END AS "RecordClassName" FROM "ImageGalleryAlbum" WHERE (ParentID = 16) ORDER BY Created DESC LIMIT 5 Unknown column 'ParentID' in 'where clause'
GET /?flush=1Line 536 in /home/espace/public_html/sapphire/core/model/MySQLDatabase.php
Source527 }
528
529 function databaseError($msg, $errorLevel = E_USER_ERROR) {
530 // try to extract and format query
531 if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
532 $formatter = new SQLFormatter();
533 $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
534 }
535
536 user_error($msg, $errorLevel);
537 }
538
539 /**
540 * Return a boolean type-formatted string
541 *
542 * @param array $values Contains a tokenised list of info about this data typeTrace
* Couldn't run query: SELECT "ImageGalleryAlbum"."ClassName", "ImageGalleryAlbum"."Created", "ImageGalleryAlbum"."LastEdited", "ImageGalleryAlbum"."AlbumName", "ImageGalleryAlbum"."Description", "ImageGalleryAlbum"."SortOrder", "ImageGalleryAlbum"."CoverImageID", "ImageGalleryAlbum"."ImageGalleryPageID", "ImageGalleryAlbum"."FolderID", "ImageGalleryAlbum"."ID", CASE WHEN "ImageGalleryAlbum"."ClassName" IS NOT NULL THEN "ImageGalleryAlbum"."ClassName" ELSE 'ImageGalleryAlbum' END AS "RecordClassName" FROM "ImageGalleryAlbum" WHERE (ParentID = 16) ORDER BY Created DESC LIMIT 5 Unknown column 'ParentID' in 'where clause'
Line 536 of MySQLDatabase.php
* MySQLDatabase->databaseError(Couldn't run query: SELECT "ImageGalleryAlbum"."ClassName", "ImageGalleryAlbum"."Created", "ImageGalleryAlbum"."LastEdited", "ImageGalleryAlbum"."AlbumName", "ImageGalleryAlbum"."Description", "ImageGalleryAlbum"."SortOrder", "ImageGalleryAlbum"."CoverImageID", "ImageGalleryAlbum"."ImageGalleryPageID", "ImageGalleryAlbum"."FolderID", "ImageGalleryAlbum"."ID", CASE WHEN "ImageGalleryAlbum"."ClassName" IS NOT NULL THEN "ImageGalleryAlbum"."ClassName" ELSE 'ImageGalleryAlbum' END AS "RecordClassName" FROM "ImageGalleryAlbum" WHERE (ParentID = 16) ORDER BY Created DESC LIMIT 5 | Unknown column 'ParentID' in 'where clause',256)
Line 134 of MySQLDatabase.php
* MySQLDatabase->query(SELECT "ImageGalleryAlbum"."ClassName", "ImageGalleryAlbum"."Created", "ImageGalleryAlbum"."LastEdited", "ImageGalleryAlbum"."AlbumName", "ImageGalleryAlbum"."Description", "ImageGalleryAlbum"."SortOrder", "ImageGalleryAlbum"."CoverImageID", "ImageGalleryAlbum"."ImageGalleryPageID", "ImageGalleryAlbum"."FolderID", "ImageGalleryAlbum"."ID", CASE WHEN "ImageGalleryAlbum"."ClassName" IS NOT NULL THEN "ImageGalleryAlbum"."ClassName" ELSE 'ImageGalleryAlbum' END AS "RecordClassName" FROM "ImageGalleryAlbum" WHERE (ParentID = 16) ORDER BY Created DESC LIMIT 5,256)
Line 127 of DB.php
* DB::query(SELECT "ImageGalleryAlbum"."ClassName", "ImageGalleryAlbum"."Created", "ImageGalleryAlbum"."LastEdited", "ImageGalleryAlbum"."AlbumName", "ImageGalleryAlbum"."Description", "ImageGalleryAlbum"."SortOrder", "ImageGalleryAlbum"."CoverImageID", "ImageGalleryAlbum"."ImageGalleryPageID", "ImageGalleryAlbum"."FolderID", "ImageGalleryAlbum"."ID", CASE WHEN "ImageGalleryAlbum"."ClassName" IS NOT NULL THEN "ImageGalleryAlbum"."ClassName" ELSE 'ImageGalleryAlbum' END AS "RecordClassName" FROM "ImageGalleryAlbum" WHERE (ParentID = 16) ORDER BY Created DESC LIMIT 5,256)
Line 386 of SQLQuery.php
* SQLQuery->execute()
Line 2735 of DataObject.php
* DataObject->instance_get(ParentID = 16,Created DESC,,5,DataObjectSet)
Line 2713 of DataObject.php
* DataObject::get(ImageGalleryAlbum,ParentID = 16,Created DESC,,5)
Line 20 of HomePage.php
* HomePage_Controller->LatestAlbums()
Line 369 of ViewableData.php
* ViewableData->obj(LatestAlbums)
Line 71 of .cache.home.espace.public_html.themes.ea.templates.Layout.HomePage.ss
* include(/tmp/silverstripe-cache-home-espace-public_html/.cache.home.espace.public_html.themes.ea.templates.Layout.HomePage.ss)
Line 420 of SSViewer.php
* SSViewer->process(HomePage_Controller,Zend_Cache_Frontend_Output)
Line 411 of SSViewer.php
* SSViewer->process(HomePage_Controller)
Line 202 of Controller.php
* Controller->handleAction(SS_HTTPRequest)
Line 137 of RequestHandler.php
* RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
* Controller->handleRequest(SS_HTTPRequest)
Line 199 of ContentController.php
* ContentController->handleRequest(SS_HTTPRequest)
Line 67 of ModelAsController.php
* ModelAsController->handleRequest(SS_HTTPRequest)
Line 111 of RootURLController.php
* RootURLController->handleRequest(SS_HTTPRequest)
Line 281 of Director.php
* Director::handleRequest(SS_HTTPRequest,Session)
Line 124 of Director.php
* Director::direct(/)
Line 127 of main.php -
Re: Latest albums on frontpage

10 August 2010 at 5:57am Last edited: 10 August 2010 6:00am
it no longer shows error when I changed the function in frontpage.php to the following:
function LatestAlbums($num=5) {
$albums = DataObject::get_one("ImageGalleryPage");
return ($albums) ? DataObject::get("ImageGalleryAlbum", "ID = $albums->ID", "Created DESC", "", $num) : false;
}but still nothing shows in frontpage.. !
-
Re: Latest albums on frontpage

10 August 2010 at 6:05am
Your query is built wrong..
function LatestAlbums($num=5) {
$page = DataObject::get_one("ImageGalleryPage");
return ($page) ? DataObject::get("ImageGalleryAlbum", "ImageGalleryPageID = $page->ID", "Created DESC", "", $num) : false;
}Even simpler:
public function LatestAlbums($num = 5) {
if($page = DataObject::get_one("ImageGalleryPage)) {
return $page->Albums(null, "Created DESC", null, $num);
}
} -
Re: Latest albums on frontpage

10 August 2010 at 6:27am
Thanks it works and shows albums from the first gallery, now because I need to show the latest albums from the main two galleries. I'm thinking of a way to return albums from both galleries..
thanks
| 1055 Views | ||
| Go to Top | Next > |

