• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Getting Started Assignment 8-10

Guest
Oct 11, 2017 Oct 11, 2017

Copy link to clipboard

Copied

Hi,

Just recently I started this tutorial for CFML. Going through this course was pretty straightforward and almost without a hassle. But now I have hit a brick wall at using coldfusion components. I followed the instructions in the video and the assignment but I stumble upon this error and cant figure out what is going wrong.

As I am adding the references to the different functions in the component i stumble upon an error. The reference to the getNewsYears function is at the top of my code(as the assignments says). But the output is somewhere at the bottom. The Error below keeps popping up.

I cannot find any info on frequent mistakes made during the tutorial. Can anybody see what I am doing wrong?

2017-10-11_10h27_25.png

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 11, 2017 Oct 11, 2017

Copy link to clipboard

Copied

This seems like a spelling mistake. You will need to show your code though so we can see.

This normally means the rsNewsYears does not exists. Check the name you gave the query further up the code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 11, 2017 Oct 11, 2017

Copy link to clipboard

Copied

Hi thanks for your reaction! I tried looking for spelling errors but didnt find anything.

This is the news.cfm code

<!---Instance newsService--->

<cfset newsService = createObject('component', 'cfTraining.components.newsService') />

<!---Get news years--->

<cfset rsNewYears = newsService.getNewsYears()/>

<cfmodule template="customTags/front.cfm" title="HD street band - News" >

  <div id="pageBody">

    <div id="calendarContent">

    <cfif isDefined('url.newsID') >

    <!---Output of a single news article--->

    <cfset rsSingleNews = newsService.getNewsByID(url.newsID) />

    <cfoutput>

    <h1>#rsSingleNews.FLD_NEWSTITLE#</h1>

    <p class ="metadata"> Published on #dateformat(rsSingleNews.FLD_NEWSCREATIONDATE, 'mmm dd yyyy')#

    by #rsSingleNews.FLD_USERFIRSTNAME# #rsSingleNews.FLD_USERLASTNAME#</p>

    #rsSingleNews.FLD_NEWSCONTENT#

    </cfoutput>

  

    <cfelseif isDefined('url.year')>

<cfset rsNewsOfYear = newsService.getNewsForYear(url.year) />

<h1> All the news of year<cfoutput > #url.year#</cfoutput></h1>

      <table>

      <!---Output  news in a table--->

      <cfoutput query="rsNewsOfYear" >

      <tr>

      <td>#dateFormat(FLD_NEWSCREATIONDATE,'mm dd yyyy')#</td>

      <td>#FLD_NEWSTITLE#</td>

      <td><a href= "news.cfm?newsID=#FLD_NEWSID#">Read More</a>></td>

      </tr>

      </cfoutput>

      </table>

    <cfelse>

<!---Get all news--->

<cfset rsAllNews = newsService.getLatestNews()/>

  <h1> News</h1>

  <table>

    <!---Output  news in a table--->

    <cfoutput query="rsAllNews">

      <tr>

      <td>#dateFormat(FLD_NEWSCREATIONDATE, 'mmm dd yyyy')#</td>

      <td>#FLD_NEWSTITLE#</td>

      <td><a href="news.cfm?newsID=#FLD_NEWSID#">Read More</a></td>

      </tr>

    </cfoutput>

  </table>

  </cfif>

</div>

<div id="calendarSideBar">

<h1>News archive</h1>

  <ul>

    <cfoutput query="rsNewsYears" group="fld_newsYear" >

      <li><a href="news.cfm?year=#fld_newsYear#">#fld_newsYear#</a></li>

    </cfoutput>

  </ul>

  <p class="alignRight"> </p>

</div>

  </div>

</cfmodule>

This is the newsService.cfc

<cfcomponent output="false">

<!---getNewsForYear()method --->

<cffunction name="getNewsForYear" access="public" output="false" returntype="query">

<cfargument name="year" type="numeric" required="true" />

<cfset var rsNewsOfYear = ''/>

<cfquery datasource= "hdStreet" name= "rsNewsOfYear">

    SELECT FLD_NEWSTITLE, FLD_NEWSCREATIONDATE, FLD_NEWSID

    FROM TBL_NEWS

    WHERE YEAR(FLD_NEWSCREATIONDATE) = #arguments.year#

    ORDER BY FLD_NEWSCREATIONDATE DESC

    </cfquery>

    <cfreturn rsNewOfYear/>

</cffunction>

<!---getNewsByID()method --->

<cffunction name="getNewsByID" access="public" output="false" returntype="query">

<cfargument name="newsID" type="numeric" required="true" />

<cfset var rsSingleNews = ''/>

<cfquery  datasource= "hdStreet" name= "rsSingleNews">

    SELECT TBL_NEWS.FLD_NEWSID, TBL_NEWS.FLD_NEWSCONTENT, TBL_NEWS.FLD_NEWSTITLE, TBL_NEWS.FLD_NEWSCREATIONDATE, TBL_USERS.FLD_USERFIRSTNAME, TBL_USERS.FLD_USERLASTNAME

    FROM TBL_NEWS INNER JOIN TBL_USERS ON TBL_NEWS.FLD_NEWSAUTHOR = TBL_USERS.FLD_USERID

    WHERE FLD_NEWSID = #arguments.newsID#

    </cfquery>

    <cfreturn rsSingleNews/>

</cffunction>

<!---getLatestNews()method --->

<cffunction name="getLatestNews" access="public" output="false" returntype="query">

<cfset var rsAllNews = ''/>

<cfquery datasource = "hdStreet" name ="rsAllNews" >

SELECT FLD_NEWSTITLE, FLD_NEWSCREATIONDATE, FLD_NEWSID

FROM TBL_NEWS

ORDER BY FLD_NEWSCREATIONDATE DESC

</cfquery>

<cfreturn rsAllNews/>

</cffunction>

<!---getNewsYears()method --->

<cffunction name="getNewsYears" access="public" output = "false" returntype="query">

<cfset var rsNewsYears = ''/>

<cfquery  datasource= "hdStreet" name= "rsNewsYears" >

SELECT YEAR (TBL_NEWS.FLD_NEWSCREATIONDATE) AS fld_newsYear

FROM TBL_NEWS

ORDER BY TBL_NEWS.FLD_NEWSCREATIONDATE DESC

</cfquery>

<cfreturn rsNewsYears/>

</cffunction>

</cfcomponent>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 11, 2017 Oct 11, 2017

Copy link to clipboard

Copied

The only place you have defined this before is further up but its a different spelling - rsNewYears is not rsNewsYears as you are using on the error line

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 11, 2017 Oct 11, 2017

Copy link to clipboard

Copied

LATEST

Hahaha that did the trick. I dont know how I missed it. Thanks a bunch!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation