我通過learncfinaweek.com學習ColdFusion和想幫助克服這個困難:元素名稱是博文的ColdFusion未定義
元素title在網誌文章 未定義用C發生錯誤:/ ColdFusion11/cfusion/wwwroot文件/ learncfinaweek/chapter1solution/admin/content/blog/listblogpost.cfm:line 34
我認爲「未定義在BLOGPOST」是指BlogPost.cfc,下面的底部頁面。那是對的嗎?
第一個是listblogpost.cfm
<cfimport taglib="../../customTags" prefix="ct" />
<ct:securityCheck redirectPage="#cgi.script_name#"/>
<cfset adminPath = createObject('learncfinaweek.chapter1solution.admin.cfc.system').getBasePath( cgi.script_name) />
<!--- Pull Blog Posts --->
<cfset blogPosts=EntityLoad('BlogPost') />
<cfoutput>
<ct:layout section="blog">
<ct:navigation section="blog" active="post"/>
<div class="span10">
<h2>Blog</h2>
<form class="navbar-form pull-right">
<a class="btn btn-primary" href="<cfoutput>#adminPath#</cfoutput>/content/blog/editblogpost.cfm">
<i class="icon-plus icon-white"></i>
New Blog Post
</a>
</form>
<table class="table table-hover">
<thead>
<tr>
<th>Title</th>
<th>Publish Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<cfloop array="#blogPosts#" index="blogPost">
<tr>
<td>
<!--- Title --->
#blogPost.title#
</td>
<td>
<!--- Date Posted --->
#dateFormat(blogPost.datePosted,"mm/dd/yyyy")#
</td>
<td>
<!--- Edit Post --->
<a href="#adminPath#/content/blog/editblogpost.cfm?id=#blogPost.id#"><i class="icon-edit"></i></a>
</td>
</tr>
</cfloop>
</tbody>
</table>
</div>
</ct:layout>
</cfoutput>
這裏是editblogpost.cfm頁:
<cfimport taglib="../../customTags" prefix="ct" />
<ct:securityCheck redirectPage="#cgi.script_name#"/>
<cfparam name="url.id" default="0" />
<cfparam name="form.submitted" default="0" />
<cfparam name="form.id" default="0" />
<cfparam name="form.title" default="" />
<cfparam name="form.summary" default="" />
<cfparam name="form.body" default="" />
<cfparam name="form.datePosted" default="" />
<cfparam name="form.categories" default="" />
<cfset errorBean = createObject('learncfinaweek.chapter1solution.admin.cfc.errorBean').init() />
<cfif form.submitted>
<!--- check if data is valid--->
<cfif !len(trim(form.title))>
<cfset errorBean.addError('Title is required','title') />
</cfif>
<cfif !len(trim(form.summary))>
<cfset errorBean.addError('A summary is required','startDate') />
</cfif>
<cfif !len(trim(form.body))>
<cfset errorBean.addError('You need to provide a body','details') />
</cfif>
<cfif !len(trim(form.datePosted))>
<cfset errorBean.addError('You need to provide a release date','details') />
</cfif>
<!--- Only process if there are no errors --->
<cfif !errorBean.hasErrors()>
<cfif val(form.id)>
<!--- Edit Entity --->
<cfset blogpost=EntityLoad('BlogPost',form.id,true) />
<cfset blogPost.title = form.title />
<cfset blogPost.summary = form.summary />
<cfset blogPost.body = form.body />
<cfset blogPost.datePosted = form.datePosted />
<cfset blogPost.modifiedDateTime = now() />
<cfloop array="#blogPost.getCategories()#" index="category">
<cfset entityDelete(category) />
</cfloop>
<cfelse>
<!--- Create Entity --->
<cfset blogPost=EntityNew('BlogPost') />
<cfset blogPost.title = form.title />
<cfset blogPost.summary = form.summary />
<cfset blogPost.body = form.body />
<cfset blogPost.datePosted = form.datePosted />
<cfset blogPost.createdDateTime = now() />
</cfif>
<cfset entitySave(blogPost) />
<!--- Add Category to Entity --->
<cfloop list="#form.categories#" index="categoryID">
<cfset blogPostCategory = EntityNew('blogPostCategory') />
<cfset blogCategory = EntityLoad('blogCategory',categoryID,true) />
<cfset blogPostCategory.blogCategory = blogCategory />
<cfset blogPostCategory.blogPost = blogPost />
<cfset entitySave(blogPostCategory) />
</cfloop>
<cfset ormFlush() />
<cflocation url="listblogpost.cfm?message=#urlencodedformat('Blog Post Saved')#" addtoken="false" />
</cfif>
</cfif>
<cfif val(url.id)>
<!--- Get Entity Data --->
<cfset blogPost = EntityLoad('BlogPost',url.id,true) />
<cfset form.id = blogPost.id />
<cfset form.title = blogPost.title />
<cfset form.summary = blogPost.summary />
<cfset form.body = blogPost.body />
<cfset form.datePosted = blogPost.datePosted />
<cfset form.categories = blogPost.categoryids />
</cfif>
<cfset categories = entityLoad('BlogCategory') />
<cfoutput>
<ct:layout section="blog">
<ct:navigation section="blog" active="post"/>
<div class="span10">
<cfif val(url.id)>
<h2>Edit Blog Post</h2>
<cfelse>
<h2>Add Blog Post</h2>
</cfif>
<cfif errorBean.hasErrors()>
<div class="alert alert-error">
<strong>Error</strong><br />
The following errors occured:
<ul>
<cfloop array="#errorBean.getErrors()#" index="error">
<li>#error.message#</li>
</cfloop>
</ul>
</div>
</cfif>
<form class="form-horizontal" action="#cgi.script_name#" method="post">
<div class="control-group">
<label class="control-label" for="title">Title</label>
<div class="controls">
<input type="text" id="title" name="title" va lue="#form.title#">
</div>
</div>
<div class="control-group">
<label class="control-label" for="title">Summary</label>
<div class="controls">
<textarea rows="6" id="summary" name="summary" class="input-xlarge">#form.summary#</textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="title">Body</label>
<div class="controls">
<textarea rows="3" id="body" name="body" class="wysiwyg">#form.body#</textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="details">Publish Date</label>
<div class="controls">
<input type="text" id="datePosted" name="datePosted" class="datepicker" value="#dateFormat(form.datePosted,'mm/dd/yyyy')#">
</div>
</div>
<div class="control-group">
<label class="control-label" for="details">Categories</label>
<div class="controls">
<label class="checkbox">
<cfloop array="#categories#" index="category">
<input type="checkbox" name="Categories" value="#category.id#"
<cfif listfind(form.categories,category.id)>checked</cfif>>#category.name#<br />
</cfloop>
</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
<input type="hidden" name="submitted" value="1" />
<input type="hidden" name="id" value="#url.id#" />
</form>
</div>
</ct:layout>
</cfoutput>
的blogPost.cfc頁:
component persistent="true" {
Property name="id" column="blogpostid" fieldtype="id" generator="increment";
Property name="title" ormtype="text";
Property name="summary" ormtype="text";
Property name="body" ormtype="text";
Property name="datePosted" ormtype="timestamp";
Property name="createdDateTime" ormtype="timestamp";
Property name="modifiedDateTime" ormtype="timestamp";
Property name="deleted" ormtype="boolean";
Property name="comments" singularname="comment" fieldtype="one-to-many" cfc="blogComment" fkcolumn="blogpostid" cascade="all";
Property name="categories" fieldtype="one-to-many" cfc="blogPostCategory" fkcolumn="blogpostid";
public string function getCategoryIDs(){
var categoryList = '';
if(hasCategories()){
for(var categoryPost in getCategories()){
categoryList = listAppend(categoryList, categoryPost.blogCategory.id);
}
}
return categoryList;
}
public string function getCategoryNames(){
var categoryList = '';
if(hasCategories()){
for(var categoryPost in getCategories()){
categoryList = listAppend(categoryList, categoryPost.blogCategory.name,', ');
}
}
return categoryList;
}
}
是否有可能通過創建分類頁面來吹掉與上面不同的東西?我應該把類別頁面放在這裏嗎? – DavidC