Please login to continue

3.10.4 Métodos de la vista

Los métodos de la Vista están disponibles para todos los archivos de vistas, elementos y plantillas. Para llamar a cualquier método de la vista utilice: $this->method()

3.10.4.1 set()

set(string $var, mixed $value)

Las Vistas tienen un metodo set() que es análogo al set() encontrado en los objetos Controller. Te permite agregar variables al viewVars. Usando set() desde tu archivo de vista, agregará las variables a la capa (layout) y elementos (elements) que luego serán renderizados. Ver Controller::set() para mas información en el uso de set().

En tu archivo vista puedes hacer

	$this->set('activeMenuButton', 'posts');
  1. $this->set('activeMenuButton', 'posts');

Luego en tu capa (layout) la variable $activeMenuButton estará disponible y contendrá el valor: 'posts'.

3.10.4.2 getVar()

getVar(string $var)

Obtiene el valor de la viewVar con el nombre $var

3.10.4.3 getVars()

getVars()

Devuelve una lista de todas las variables de vistas disponibles en la renderización actual. Devuelve una matriz con los nombres de las variables.

3.10.4.4 error()

Todavia no hay una traducion de este texto. Por favor ayudanos y traducirla.. Mas info sobre traduciones

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');
  1. $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()

Todavia no hay una traducion de este texto. Por favor ayudanos y traducirla.. Mas info sobre traduciones

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()

Todavia no hay una traducion de este texto. Por favor ayudanos y traducirla.. Mas info sobre traduciones

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'
  1. $uuid = $this->uuid('form', array('controller' => 'posts', 'action' => 'index'));
  2. //$uuid contains 'form0425fe3bad'

3.10.4.7 addScript()

Todavia no hay una traducion de este texto. Por favor ayudanos y traducirla.. Mas info sobre traduciones

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.