Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Latest albums on frontpage

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 1395 Views
  • sajok
    Avatar
    Community Member
    82 Posts

    Latest albums on frontpage Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Latest albums on frontpage Link to this post

    Get your site into dev mode so we can see the error!

  • sajok
    Avatar
    Community Member
    82 Posts

    Re: Latest albums on frontpage Link to this post

    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=1

    Line 33 in /home/espace/public_html/sapphire/core/Cookie.php
    Source

    24          $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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Latest albums on frontpage Link to this post

    Tu as d'éspace blanche quelque place.. Fait certain que tu n'as pas fermé de tags PHP!

  • sajok
    Avatar
    Community Member
    82 Posts

    Re: Latest albums on frontpage Link to this post

    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=1

    Line 536 in /home/espace/public_html/sapphire/core/model/MySQLDatabase.php
    Source

    527    }
    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 type

    Trace

    * 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

  • sajok
    Avatar
    Community Member
    82 Posts

    Re: Latest albums on frontpage Link to this post

    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.. !

  • UncleCheese
    Avatar
    4085 Posts

    Re: Latest albums on frontpage Link to this post

    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);
    }
    }

  • sajok
    Avatar
    Community Member
    82 Posts

    Re: Latest albums on frontpage Link to this post

    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

    1395 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.