Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

nette-components

БесплатноБез исполняемых скриптовНе проверен

Invoke before writing or modifying a Nette component (Control), a component factory or a signal handler, and before any AJAX/snippet code. Use when working…

netteот nette★ 47 звёзд на GitHub

Об этом скилле

Nette Components, Signals and Snippets

A component is a descendant of Nette\Application\UI\Control, and the presenter is itself a Control (ComponentModel\Component -> Container -> UI\Component -> UI\Control -> UI\Presenter), so everything below applies to both. Related skills: nette-forms (controls, validation, onSuccess), nette-architecture (where components live), latte-templates ({control}/{snippet} syntax), nette-configuration (generated factories), frontend-development (Naja on the JS side).

Component Factories

Any container (presenter or control) creates children lazily through createComponent<Name>():

protected function createComponentPoll(): PollControl
{
	return new PollControl($this->items);
}

The factory is never called directly. It fires on first access – $this->getComponent('poll') or the equivalent $this['poll'] (the ComponentModel\ArrayAccess trait), which is what {control poll} does. An untouched component is never built.

  • The name starts with a lowercase letter. Container::createComponent() requires ucfirst($name) !== $name, so asking for Poll never reaches createComponentPoll().
  • The factory receives the name as its first argument, and may either return the component or add it itself with addComponent(); doing neither throws Nette\UnexpectedValueException.
  • Names match #^[a-zA-Z0-9_]+$#D – no hyphen in a name, - is the tree separator: $this['cart-form'] means "child form of child cart", nesting to any depth.
  • Not presenter-only: a Control defines createComponent<Name>() for its own children the same way.
  • For components with dependencies, inject a factory (a class or a DI-generated interface) and call it from createComponent<Name>() – see nette-configuration for implement:.

Signals

A signal performs an action on the current page. It calls handle<Signal>() on the component addressed by the do query parameter (?do=cart-remove); matching is case-insensitive.

public function handleDelete(int $id): void   // ?do=delete&id=…
{
	$this->facade->delete($id);
	$this->redirect('this');
}

Where signals run – after the action phase and canonicalization, before any render method, not "in the action phase" (the full lifecycle order is in nette-architecture). Consequence: a handler can prepare data that render<View>() then respects (if (!isset($this->template->articles)) …).

  • A signal cannot target another presenter or action; it re-runs the current request plus the handler. A missing handler throws BadSignalException (403 page).
  • Signal parameters come from the URL and from the POST body, but a URL parameter of the same name wins. They share one namespace with action and persistent parameters.
  • A form submit is not a signal. UI\Form::signalReceived() accepts only the signal submit and turns it into onSubmit/onSuccess; any other signal name on a form throws BadSignalException. Never write handleSubmit() for a form – put the logic in an onSuccess handler (see nette-forms).

Links Inside a Component

In a component template, n:href, {link} and $this->link()/$this->redirect() always mean a signal of that component, with or without ! – LinkGenerator switches to signal mode as soon as the link source is not a Presenter.

{* inside a component template *}
<a n:href="click!">signal</a>          {* the ! is optional here *}
<a n:href="subcomponent:click!">signal of a child</a>
<a href={plink Home:default}>presenter link</a>

{plink} = presenter link: it compiles to $this->global->uiPresenter->link(...), where {link} and n:href compile to $this->global->uiControl->link(...). It is not "absolute" and not "persistent" – an absolute URL comes from the // prefix, which works with {link} too. In PHP the equivalent is $this->getPresenter()->link('Home:default').

The only non-signal destination inside a component is 'this' (current presenter + action): $this->redirect('this'). Arguments cannot be passed to this!.

Persistent Parameters

A persistent parameter survives across requests in the URL, automatically, including links generated by other components on the page.

use Nette\Application\Attributes\Persistent;

class ItemList extends Control
{
	#[Persistent]
	public int $page = 1;   // must be public, non-static, typed
}

loadState() writes the URL value into the property and answers a type mismatch with a 404 – override it for range checks; saveState() is the reverse direction. In links, <a n:href="this page: $page + 1"> changes the value and page: null resets it to the default (drops it from the URL).

Persistent components use the same attribute on the presenter class, listing component names; their persistent parameters then survive across actions and presenters, subcomponents included:

#[Persistent('
Полный SKILL.md на GitHub

Установить nette-components в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл nette-components?

Invoke before writing or modifying a Nette component (Control), a component factory or a signal handler, and before any AJAX/snippet code. Use when working with createComponent<Name>(), $this['name'], handle<Signal>() methods, signal links (n:href="click!", link('click')), {plink} in a component template, persistent parameters (#[Persistent]) and persistent components, redrawControl()/isControlInvalid(), {snippet} and {snippetArea}, dynamic snippets, isAjax() and $this->payload, Multiplier, or the component tree (getComponents(), getComponentTree(), monitor(), lookup(), $onAnchor). Also trigger for "snippet is not redrawing", BadSignalException, or "how do I do AJAX in Nette".

Как установить скилл nette-components?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл nette-components запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить nette-components с