Neuron-PHP

Tags extends Content

Admin tag management controller.

Attributes
#[RouteGroup]
$prefix: '/admin'
$filters: ['auth']

Table of Contents

Properties

$_sessionManager  : SessionManager
$_settings  : SettingManager
$_app  : IMvcApplication
$_description  : string
$_name  : string
$_router  : Router|null
$_rssUrl  : string
$_slugGenerator  : SlugGenerator
$_tagRepository  : ITagRepository
$_title  : string
$_url  : string

Methods

__call()  : string|null
Magic method to provide Rails-style URL helper methods in controllers.
__construct()  : mixed
create()  : string
Show create tag form
destroy()  : never
Delete tag
edit()  : string
Show edit tag form
getApplication()  : IMvcApplication
getDescription()  : string
getName()  : string
getRouter()  : Router
getRssUrl()  : string
Getters and Setters
getTitle()  : string
getUrl()  : string
index()  : string
List all tags
markdown()  : string
Render a markdown page.
register()  : void
This method registers routes for any of the standard methods that are currently implemented in the class.
renderHtml()  : string
Renders an HTML response.
renderHtmlWithCacheKey()  : string
Render HTML with separate cache key data.
renderJson()  : string
Renders a JSON response.
renderMarkdown()  : string
Renders a Markdown response.
renderMarkdownWithCacheKey()  : string
Render Markdown with separate cache key data.
renderXml()  : string
Renders an XML response.
setApplication()  : Base
setDescription()  : $this
setName()  : $this
setRouter()  : Base
setRssUrl()  : Content
Set the RSS URL for the site.
setTitle()  : $this
setUrl()  : Content
Set the URL for the site.
store()  : never
Store new tag
update()  : never
Update tag
createDto()  : Dto
Create a DTO from a YAML configuration file.
flash()  : void
Set a flash message for the next request.
getControllerName()  : string
Get the controller name for cache key generation.
getControllerViewPath()  : string
Get the controller view path accounting for namespace hierarchy.
getSessionManager()  : SessionManager
Get the session manager and ensure session is started.
getViewCache()  : string|null
Get cached view content if available.
getViewCacheByKey()  : string|null
Get cached view content using only cache key data.
hasViewCache()  : bool
Check if a view cache exists for the given page and data.
hasViewCacheByKey()  : bool
Check if a view cache exists using only cache key data.
initializeCsrfToken()  : void
Initialize CSRF token and store in Registry for template access.
initializeViewCache()  : ViewCache|null
Initialize ViewCache if not already present in Registry.
injectHelpers()  : array<string|int, mixed>
Inject URL helpers and other view helpers into view data.
isCacheEnabledByDefault()  : bool
Check if cache is enabled by default in system settings.
mapRequestToDto()  : void
Map HTTP request data to a DTO.
redirect()  : never
Redirect to a named route with optional flash message.
redirectBack()  : never
Redirect back to the previous page or a fallback URL.
redirectToUrl()  : never
Redirect to a URL path with optional flash message.
registerAdd()  : void
registerCreate()  : void
registerDelete()  : void
registerEdit()  : void
registerIndex()  : void
registerShow()  : void
registerUpdate()  : void
routeExists()  : bool
Check if a named route exists.
urlFor()  : string|null
Generate a relative URL for a named route.
urlForAbsolute()  : string|null
Generate an absolute URL for a named route.
urlHelper()  : UrlHelper|null
Create a new UrlHelper instance for use in controllers.
validationError()  : never
Handle validation errors by redirecting with flash message.
view()  : ViewContext
Create a new fluent ViewContext for building and rendering views.
generateSlug()  : string
Generate slug from name
storeCachedView()  : void
Store rendered content in view cache.

Properties

$_description

private string $_description = ''

$_name

private string $_name = 'Blahg'

$_rssUrl

private string $_rssUrl = 'example.com/blog/rss'

$_title

private string $_title = 'Blahg'

$_url

private string $_url = 'example.com/bog'

Methods

__call()

Magic method to provide Rails-style URL helper methods in controllers.

public __call(string $method, array<string|int, mixed> $arguments) : string|null

Supports patterns like:

  • $this->userProfilePath(['id' => 123]) -> generates relative URL for 'user_profile' route
  • $this->userProfileUrl(['id' => 123]) -> generates absolute URL for 'user_profile' route
Parameters
$method : string

The method name (e.g., 'userProfilePath', 'userProfileUrl')

$arguments : array<string|int, mixed>

Method arguments, first should be parameters array

Tags
throws
BadMethodCallException

If a method pattern is not recognized

example
// In a controller method:
$profilePath = $this->userProfilePath(['id' => $userId]);
$absoluteUrl = $this->userProfileUrl(['id' => $userId]);

// Redirect to a named route:
return redirect($this->userDashboardPath());
Return values
string|null

Generated URL or null if route not found

create()

Show create tag form

public create(Request $request) : string
Parameters
$request : Request
Tags
throws
Exception
Attributes
#[Get]
'/tags/create'
$name: 'admin_tags_create'
Return values
string

destroy()

Delete tag

public destroy(Request $request) : never
Parameters
$request : Request
Tags
throws
Exception
Attributes
#[Delete]
'/tags/:id'
$name: 'admin_tags_destroy'
$filters: ['csrf']
Return values
never

edit()

Show edit tag form

public edit(Request|null $request) : string
Parameters
$request : Request|null
Tags
throws
Exception
Attributes
#[Get]
'/tags/:id/edit'
$name: 'admin_tags_edit'
Return values
string

getDescription()

public getDescription() : string
Return values
string

getName()

public getName() : string
Return values
string

getRssUrl()

Getters and Setters

public getRssUrl() : string
Return values
string

getTitle()

public getTitle() : string
Return values
string

getUrl()

public getUrl() : string
Return values
string

index()

List all tags

public index(Request $request) : string
Parameters
$request : Request
Tags
throws
Exception
Attributes
#[Get]
'/tags'
$name: 'admin_tags'
Return values
string

markdown()

Render a markdown page.

public markdown(Request $request) : string
Parameters
$request : Request
Tags
throws
NotFound
throws
CommonMarkException
Return values
string

register()

This method registers routes for any of the standard methods that are currently implemented in the class.

public static register(IMvcApplication $app[, string $route = '' ]) : void

Index Add Show Create Edit Update Delete

Parameters
$app : IMvcApplication
$route : string = ''
Tags
throws
BadRequestMethod

renderHtml()

Renders an HTML response.

public renderHtml(HttpResponseStatus $responseCode[, array<string|int, mixed> $data = [] ][, string $page = "index" ][, string $layout = "default" ][, bool|null $cacheEnabled = null ]) : string
Parameters
$responseCode : HttpResponseStatus
$data : array<string|int, mixed> = []
$page : string = "index"
$layout : string = "default"
$cacheEnabled : bool|null = null
Tags
throws
NotFound
Return values
string

renderHtmlWithCacheKey()

Render HTML with separate cache key data.

public renderHtmlWithCacheKey(HttpResponseStatus $responseCode[, array<string|int, mixed> $viewData = [] ][, array<string|int, mixed> $cacheKeyData = [] ][, string $page = "index" ][, string $layout = "default" ][, bool|null $cacheEnabled = null ]) : string

Allows checking/using cache without fetching full view data.

Parameters
$responseCode : HttpResponseStatus

HTTP response status

$viewData : array<string|int, mixed> = []

Full data for rendering (can be empty if using cache)

$cacheKeyData : array<string|int, mixed> = []

Minimal data for cache key generation

$page : string = "index"

Page template name

$layout : string = "default"

Layout template name

$cacheEnabled : bool|null = null

Whether to enable caching

Tags
throws
NotFound
Return values
string

Rendered HTML content

renderJson()

Renders a JSON response.

public renderJson(HttpResponseStatus $responseCode[, array<string|int, mixed> $data = [] ]) : string
Parameters
$responseCode : HttpResponseStatus
$data : array<string|int, mixed> = []
Return values
string

renderMarkdown()

Renders a Markdown response.

public renderMarkdown(HttpResponseStatus $responseCode[, array<string|int, mixed> $data = [] ][, string $page = "index" ][, string $layout = "default" ][, bool|null $cacheEnabled = null ]) : string
Parameters
$responseCode : HttpResponseStatus
$data : array<string|int, mixed> = []
$page : string = "index"
$layout : string = "default"
$cacheEnabled : bool|null = null
Tags
throws
CommonMarkException
throws
NotFound
Return values
string

renderMarkdownWithCacheKey()

Render Markdown with separate cache key data.

public renderMarkdownWithCacheKey(HttpResponseStatus $responseCode[, array<string|int, mixed> $viewData = [] ][, array<string|int, mixed> $cacheKeyData = [] ][, string $page = "index" ][, string $layout = "default" ][, bool|null $cacheEnabled = null ]) : string

Allows checking/using cache without fetching full view data.

Parameters
$responseCode : HttpResponseStatus

HTTP response status

$viewData : array<string|int, mixed> = []

Full data for rendering (can be empty if using cache)

$cacheKeyData : array<string|int, mixed> = []

Minimal data for cache key generation

$page : string = "index"

Page template name

$layout : string = "default"

Layout template name

$cacheEnabled : bool|null = null

Whether to enable caching

Tags
throws
NotFound
throws
CommonMarkException
Return values
string

Rendered Markdown content

renderXml()

Renders an XML response.

public renderXml(HttpResponseStatus $responseCode[, array<string|int, mixed> $data = [] ]) : string
Parameters
$responseCode : HttpResponseStatus
$data : array<string|int, mixed> = []
Return values
string

setDescription()

public setDescription(string $description) : $this
Parameters
$description : string
Return values
$this

setName()

public setName(string $name) : $this
Parameters
$name : string
Return values
$this

setRssUrl()

Set the RSS URL for the site.

public setRssUrl(string $rssUrl) : Content
Parameters
$rssUrl : string
Return values
Content

setTitle()

public setTitle(string $title) : $this
Parameters
$title : string
Return values
$this

setUrl()

Set the URL for the site.

public setUrl(string $url) : Content
Parameters
$url : string
Return values
Content

store()

Store new tag

public store(Request $request) : never
Parameters
$request : Request
Tags
throws
Exception
Attributes
#[Post]
'/tags'
$name: 'admin_tags_store'
$filters: ['csrf']
Return values
never

update()

Update tag

public update(Request|null $request) : never
Parameters
$request : Request|null
Tags
throws
Exception
Attributes
#[Put]
'/tags/:id'
$name: 'admin_tags_update'
$filters: ['csrf']
Return values
never

createDto()

Create a DTO from a YAML configuration file.

protected createDto(string $config) : Dto
Parameters
$config : string

Path to YAML config file relative to Dtos/ (e.g., 'auth/login-request.yaml')

Tags
throws
Exception

If DTO factory fails

Return values
Dto

flash()

Set a flash message for the next request.

protected flash(string $type, string $message) : void
Parameters
$type : string

Message type (success, error, warning, info)

$message : string

The message text

getControllerName()

Get the controller name for cache key generation.

protected getControllerName() : string

Returns the short class name (without namespace). This matches how the framework's render methods set the controller name.

Return values
string

The controller class name without namespace

getControllerViewPath()

Get the controller view path accounting for namespace hierarchy.

protected getControllerViewPath() : string

Converts controller namespace and class name to snake_case directory structure.

Examples:

  • Neuron\Cms\Controllers\Admin\Posts -> admin/posts
  • Neuron\Cms\Controllers\PostController -> post (backwards compatible with "Controller" suffix)
  • Neuron\Cms\Controllers\Dashboard -> dashboard
Return values
string

The view path (e.g., "admin/posts", "dashboard")

getViewCache()

Get cached view content if available.

protected getViewCache(string $page[, array<string|int, mixed> $data = [] ]) : string|null

Initializes ViewCache if needed.

Parameters
$page : string

The page/view name

$data : array<string|int, mixed> = []

The data that affects cache key generation

Return values
string|null

The cached content or null if not found

getViewCacheByKey()

Get cached view content using only cache key data.

protected getViewCacheByKey(string $page[, array<string|int, mixed> $cacheKeyData = [] ]) : string|null

This allows retrieving the cache without fetching full view data.

Parameters
$page : string

The page/view name

$cacheKeyData : array<string|int, mixed> = []

The minimal data that determines cache uniqueness

Return values
string|null

The cached content or null if not found

hasViewCache()

Check if a view cache exists for the given page and data.

protected hasViewCache(string $page[, array<string|int, mixed> $data = [] ]) : bool

Initializes ViewCache if needed.

Parameters
$page : string

The page/view name

$data : array<string|int, mixed> = []

The data that affects cache key generation

Return values
bool

True if a cache exists, false otherwise

hasViewCacheByKey()

Check if a view cache exists using only cache key data.

protected hasViewCacheByKey(string $page[, array<string|int, mixed> $cacheKeyData = [] ]) : bool

This allows checking cache without fetching full view data.

Parameters
$page : string

The page/view name

$cacheKeyData : array<string|int, mixed> = []

The minimal data that determines cache uniqueness

Return values
bool

True if cache exists, false otherwise

initializeCsrfToken()

Initialize CSRF token and store in Registry for template access.

protected initializeCsrfToken() : void

Should be called by controllers that render forms requiring CSRF protection.

Note: Registry is used here as a view data bag to make CSRF tokens available to templates.

initializeViewCache()

Initialize ViewCache if not already present in Registry.

protected initializeViewCache() : ViewCache|null

This allows controllers to check cache before making expensive API calls.

Return values
ViewCache|null

The ViewCache instance or null if initialization fails

injectHelpers()

Inject URL helpers and other view helpers into view data.

protected injectHelpers(array<string|int, mixed> $data) : array<string|int, mixed>

This method:

  1. Merges global view data from ViewDataProvider (if registered)
  2. Injects UrlHelper for route generation (if router available)
  3. Controller-specific data takes precedence over global data
Parameters
$data : array<string|int, mixed>

The view data array

Return values
array<string|int, mixed>

Data array with helpers and global data injected

isCacheEnabledByDefault()

Check if cache is enabled by default in system settings.

protected isCacheEnabledByDefault() : bool
Return values
bool

True if cache is enabled in settings, false otherwise

mapRequestToDto()

Map HTTP request data to a DTO.

protected mapRequestToDto(Dto $dto, Request $request) : void
Parameters
$dto : Dto

The DTO to populate

$request : Request

The HTTP request containing form data

redirect()

Redirect to a named route with optional flash message.

protected redirect(string $routeName[, array<string, mixed> $parameters = [] ][, array{0: string, 1: string}|null $flash = null ]) : never
Parameters
$routeName : string

The name of the route to redirect to

$parameters : array<string, mixed> = []

Route parameters

$flash : array{0: string, 1: string}|null = null

Optional flash message as [$type, $message]

Return values
never

redirectBack()

Redirect back to the previous page or a fallback URL.

protected redirectBack([string $fallback = '/' ][, array{0: string, 1: string}|null $flash = null ]) : never
Parameters
$fallback : string = '/'

Fallback URL if referer is not available

$flash : array{0: string, 1: string}|null = null

Optional flash message as [$type, $message]

Return values
never

redirectToUrl()

Redirect to a URL path with optional flash message.

protected redirectToUrl(string $url[, array{0: string, 1: string}|null $flash = null ]) : never
Parameters
$url : string

The URL path to redirect to

$flash : array{0: string, 1: string}|null = null

Optional flash message as [$type, $message]

Return values
never

registerAdd()

protected static registerAdd(Application $app, string $controller, string $route) : void
Parameters
$app : Application
$controller : string
$route : string
Tags
throws
BadRequestMethod

registerCreate()

protected static registerCreate(Application $app, string $controller, string $route) : void
Parameters
$app : Application
$controller : string
$route : string
Tags
throws
BadRequestMethod

registerDelete()

protected static registerDelete(Application $app, string $controller, string $route) : void
Parameters
$app : Application
$controller : string
$route : string
Tags
throws
BadRequestMethod

registerEdit()

protected static registerEdit(Application $app, string $controller, string $route) : void
Parameters
$app : Application
$controller : string
$route : string
Tags
throws
BadRequestMethod

registerIndex()

protected static registerIndex(Application $app, string $controller, string $route) : void
Parameters
$app : Application
$controller : string
$route : string
Tags
throws
BadRequestMethod

registerShow()

protected static registerShow(Application $app, string $controller, string $route) : void
Parameters
$app : Application
$controller : string
$route : string
Tags
throws
BadRequestMethod

registerUpdate()

protected static registerUpdate(Application $app, string $controller, string $route) : void
Parameters
$app : Application
$controller : string
$route : string
Tags
throws
BadRequestMethod

routeExists()

Check if a named route exists.

protected routeExists(string $routeName) : bool
Parameters
$routeName : string

The route name to check

Return values
bool

True if route exists, false otherwise

urlFor()

Generate a relative URL for a named route.

protected urlFor(string $routeName[, array<string|int, mixed> $parameters = [] ][, string|null $fallback = null ]) : string|null
Parameters
$routeName : string

The name of the route

$parameters : array<string|int, mixed> = []

Parameters to substitute in the route path

$fallback : string|null = null

Fallback URL if route not found

Return values
string|null

The generated relative URL, fallback if provided, or null if route not found

urlForAbsolute()

Generate an absolute URL for a named route.

protected urlForAbsolute(string $routeName[, array<string|int, mixed> $parameters = [] ][, string|null $fallback = null ]) : string|null
Parameters
$routeName : string

The name of the route

$parameters : array<string|int, mixed> = []

Parameters to substitute in the route path

$fallback : string|null = null

Fallback URL if route not found

Return values
string|null

The generated absolute URL, fallback if provided, or null if route not found

urlHelper()

Create a new UrlHelper instance for use in controllers.

protected urlHelper() : UrlHelper|null
Return values
UrlHelper|null

The URL helper instance or null if router not available

validationError()

Handle validation errors by redirecting with flash message.

protected validationError(string $route, array<string, array<int, string>> $errors[, array<string, mixed> $routeParams = [] ]) : never
Parameters
$route : string

Route name to redirect to

$errors : array<string, array<int, string>>

Validation errors from DTO

$routeParams : array<string, mixed> = []

Optional route parameters

Return values
never

view()

Create a new fluent ViewContext for building and rendering views.

protected view() : ViewContext

This provides a clean, chainable API for constructing view data and rendering.

Tags
example
// Basic usage
return $this->view()
    ->title('Dashboard')
    ->description('Admin Dashboard')
    ->with('posts', $posts)
    ->render('index', 'admin');

// With auto-injection
return $this->view()
    ->title('Profile')
    ->withCurrentUser()
    ->withCsrfToken()
    ->render('profile');
Return values
ViewContext

A new view context instance

generateSlug()

Generate slug from name

private generateSlug(string $name) : string

For names with only non-ASCII characters (e.g., "你好", "مرحبا"), generates a fallback slug using uniqid().

Parameters
$name : string
Tags
throws
Exception
Return values
string

storeCachedView()

Store rendered content in view cache.

private storeCachedView(string $page, array<string|int, mixed> $cacheKeyData, string $content, bool|null $cacheEnabled) : void

Handles cache initialization, temporary enablement, and error handling.

Parameters
$page : string

The page/view name

$cacheKeyData : array<string|int, mixed>

Data for cache key generation

$content : string

The rendered content to cache

$cacheEnabled : bool|null

Whether caching is explicitly enabled


        
On this page

Search results