|
- <%
- ' Auto-generated Controller: Categories
- ' Generated on 5/2/2026 9:47:37 PM
- ' Generator: generateController.vbs v1.0
- '
- ' Remember to:
- ' 1. Add to app/controllers/autoload_controllers.asp
- ' 2. Register in core/lib.ControllerRegistry.asp
- ' 3. Add routes in public/Default.asp
-
-
- Class CategoriesController_Class
- Private m_useLayout
- Private m_title
-
- Private Sub Class_Initialize()
- m_useLayout = True
- m_title = "Categories"
- End Sub
-
- Public Property Get useLayout
- useLayout = m_useLayout
- End Property
-
- Public Property Let useLayout(v)
- m_useLayout = v
- End Property
-
- Public Property Get Title
- Title = m_title
- End Property
-
- Public Property Let Title(v)
- m_title = v
- End Property
-
- '---------------------------------------------------------------
- ' Action: Index
- '---------------------------------------------------------------
- Public Sub Index()
- Dim categories
- Set categories = CategoriesRepository().FindAll
- %>
- <!--#include file="../views/Categories/index.asp" -->
- <%
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Show
- '---------------------------------------------------------------
- Public Sub Show(ByVal id)
- Dim category
- On Error Resume Next
- Set category = CategoriesRepository().FindByID(id)
- If Err.Number <> 0 Then
- Err.Clear
- On Error GoTo 0
- Response.Status = "404 Not Found"
- %>
- <!--#include file="../views/Error/NotFound.asp" -->
- <%
- Exit Sub
- End If
- On Error GoTo 0
-
- Dim categoryPosts
- Set categoryPosts = PostsRepository().Find(Array("CategoryID", id, "IsPublished", 1), "PublishedDate DESC")
- %>
- <!--#include file="../views/Categories/show.asp" -->
- <%
- End Sub
-
- '---------------------------------------------------------------
- ' Action: New
- '---------------------------------------------------------------
- Public Sub NewForm()
- %>
- <!--#include file="../views/Categories/new.asp" -->
- <%
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Create
- '---------------------------------------------------------------
- Public Sub Create()
- Dim name : name = Trim(Request.Form("Name"))
- If Len(name) = 0 Then
- Flash().AddError "Name is required."
- Response.Redirect "/categories/new"
- Exit Sub
- End If
-
- Dim category
- Set category = New POBO_Categories
-
- category.Name = name
- category.Slug = Request.Form("Slug")
- category.Description = Request.Form("Description")
-
- CategoriesRepository().AddNew category
- Flash().Success = "Category created."
- Response.Redirect "/categories"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Edit
- '---------------------------------------------------------------
- Public Sub Edit(ByVal id)
- Dim category
- On Error Resume Next
- Set category = CategoriesRepository().FindByID(id)
- If Err.Number <> 0 Then
- Err.Clear
- On Error GoTo 0
- Response.Status = "404 Not Found"
- %>
- <!--#include file="../views/Error/NotFound.asp" -->
- <%
- Exit Sub
- End If
- On Error GoTo 0
- %>
- <!--#include file="../views/Categories/edit.asp" -->
- <%
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Update
- '---------------------------------------------------------------
- Public Sub Update(ByVal id)
- Dim category
- On Error Resume Next
- Set category = CategoriesRepository().FindByID(id)
- If Err.Number <> 0 Then
- Err.Clear
- On Error GoTo 0
- Response.Status = "404 Not Found"
- %>
- <!--#include file="../views/Error/NotFound.asp" -->
- <%
- Exit Sub
- End If
- On Error GoTo 0
-
- Dim name : name = Trim(Request.Form("Name"))
- If Len(name) = 0 Then
- Flash().AddError "Name is required."
- Response.Redirect "/categories/" & Server.URLEncode(CStr(id)) & "/edit"
- Exit Sub
- End If
-
- category.Name = name
- category.Slug = Request.Form("Slug")
- category.Description = Request.Form("Description")
-
- CategoriesRepository().Update category
- Flash().Success = "Category updated."
- Response.Redirect "/categories"
- End Sub
-
- '---------------------------------------------------------------
- ' Action: Delete
- '---------------------------------------------------------------
- Public Sub Delete(ByVal id)
- CategoriesRepository().Delete id
- Flash().Success = "Category deleted."
- Response.Redirect "/categories"
- End Sub
-
- End Class
-
- ' Singleton instance
- Dim CategoriesController_Class__Singleton
- Function CategoriesController()
- If IsEmpty(CategoriesController_Class__Singleton) Then
- Set CategoriesController_Class__Singleton = New CategoriesController_Class
- End If
- Set CategoriesController = CategoriesController_Class__Singleton
- End Function
- %>
|