3.10.4 Metodi delle viste
View methods are accessible in all view, element and layout files. To call any view method use $this->method()
I metodi delle viste sono accessibili da ogni file di vista, elemento e layout. La sintassi per richiamare i metodi delle viste è $this->method()
3.10.4.1 set()
set(string $var, mixed $value)
Le viste hanno un metodo set() che è analogo al metodo set() presente negli oggetti Controller. Permette di aggiungere variabili a viewVars. L'utilizzo di set() nel file della vista aggiungerà la variabile al layout ed elementi visualizzati in seguito. Vedi Controller::set() per ulteriori informazioni sull'uso di set().
Nel file della vista si può scivere:
$this->set('activeMenuButton', 'posts');
$this->set('activeMenuButton', 'posts');
Successivamente nel layout la variabile $activeMenuButton sarà disponibile e conterrà il valore 'posts'.
3.10.4.2 getVar()
There is no translation yet for this section. Please help out and translate this.. More information about translations
getVar(string $var)
Gets the value of the viewVar with the name $var
3.10.4.3 getVars()
There is no translation yet for this section. Please help out and translate this.. More information about translations
getVars()
Gets a list of all the available view variables in the current rendering scope. Returns an array of variable names.
3.10.4.4 error()
There is no translation yet for this section. Please help out and translate this.. More information about translations
error(int $code, string $name, string $message)
Displays an error page to the user. Uses layouts/error.ctp to render the page.
$this->error(404, 'Not found', 'This page was not found, sorry');
$this->error(404, 'Not found', 'This page was not found, sorry');
This will render an error page with the title and messages specified. Its important to note that script execution is not stopped by View::error() So you will have to stop code execution yourself if you want to halt the script.
3.10.4.5 element()
There is no translation yet for this section. Please help out and translate this.. More information about translations
element(string $elementPath, array $data, bool $loadHelpers)
Renders an element or view partial. See the section on View Elements for more information and examples.
3.10.4.6 uuid()
There is no translation yet for this section. Please help out and translate this.. More information about translations
uuid(string $object, mixed $url)
Generates a unique non-random DOM ID for an object, based on the object type and url. This method is often used by helpers that need to generate unique DOM ID's for elements such as the AjaxHelper.
$uuid = $this->uuid('form', array('controller' => 'posts', 'action' => 'index'));
//$uuid contains 'form0425fe3bad'
$uuid = $this->uuid('form', array('controller' => 'posts', 'action' => 'index'));//$uuid contains 'form0425fe3bad'
3.10.4.7 addScript()
There is no translation yet for this section. Please help out and translate this.. More information about translations
addScript(string $name, string $content)
Adds content to the internal scripts buffer. This buffer is made available in the layout as $scripts_for_layout. This method is helpful when creating helpers that need to add javascript or css directly to the layout. Keep in mind that scripts added from the layout, or elements in the layout will not be added to $scripts_for_layout. This method is most often used from inside helpers, like the Javascript and Html Helpers.


























