Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit 933ef3e

Browse files
authored
Merge pull request #310 from wheels-dev/feature/my-posts-page
fix: Pass statuses struct from controller to view
2 parents 069edf6 + 6415eab commit 933ef3e

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

app/controllers/web/BlogController.cfc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,30 @@ component extends="app.Controllers.Controller" {
2626
? params.status
2727
: "all";
2828

29+
// Expose statuses to view (controller methods aren't available in views)
30+
statuses = blogStatuses();
31+
2932
var statusCountsQuery = model("Blog").findAll(
3033
select = "statusId, COUNT(*) as cnt",
31-
where = "createdBy = #userId# AND blog_posts.statusId <> #blogStatuses().TRASH#",
34+
where = "createdBy = #userId# AND blog_posts.statusId <> #statuses.TRASH#",
3235
group = "statusId"
3336
);
3437

3538
statusCounts = {"all" = 0, "draft" = 0, "published" = 0, "pending" = 0};
36-
var s = blogStatuses();
3739
for (var row in statusCountsQuery) {
3840
statusCounts.all += row.cnt;
39-
if (row.statusId == s.DRAFT) statusCounts.draft = row.cnt;
40-
else if (row.statusId == s.POSTED) statusCounts.published = row.cnt;
41-
else if (row.statusId == s.PENDING_REVIEW) statusCounts.pending = row.cnt;
41+
if (row.statusId == statuses.DRAFT) statusCounts.draft = row.cnt;
42+
else if (row.statusId == statuses.POSTED) statusCounts.published = row.cnt;
43+
else if (row.statusId == statuses.PENDING_REVIEW) statusCounts.pending = row.cnt;
4244
}
4345

44-
var where = "createdBy = #userId# AND blog_posts.statusId <> #blogStatuses().TRASH#";
46+
var where = "createdBy = #userId# AND blog_posts.statusId <> #statuses.TRASH#";
4547
if (statusFilter == "draft") {
46-
where &= " AND blog_posts.statusId = #blogStatuses().DRAFT#";
48+
where &= " AND blog_posts.statusId = #statuses.DRAFT#";
4749
} else if (statusFilter == "published") {
48-
where &= " AND blog_posts.statusId = #blogStatuses().POSTED#";
50+
where &= " AND blog_posts.statusId = #statuses.POSTED#";
4951
} else if (statusFilter == "pending") {
50-
where &= " AND blog_posts.statusId = #blogStatuses().PENDING_REVIEW#";
52+
where &= " AND blog_posts.statusId = #statuses.PENDING_REVIEW#";
5153
}
5254

5355
myBlogs = model("Blog").findAll(

app/views/web/BlogController/myPosts.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<cfscript>
2-
statuses = blogStatuses();
2+
// statuses is passed from the controller as an instance variable
33
44
function statusLabel(statusId) {
55
if (statusId == statuses.DRAFT) return "Draft";

0 commit comments

Comments
 (0)