logo

WikiJuanan: OverridingScaffoldViews ...

Inicio | Indice De Paginas | Ultimas Modificaciones | Ultimos Commentarios | Usuarios | Registrarse | Conectar:  Contraseña:  

Cake PHPCake Log


Overriding Scaffold Views
Extraido de: http://wiki.cakephp.org/tutorials:scaffolding_a_blog


Basically there are two ways to overide the views that scaffold creates:


1) provide a “scaffold.:action:.thtml” template. This reuses the scaffold controller action code. You only need to provide the app/views/:controller:/scaffold.:action:.thml


For example to override the ‘index’ view, create a file called ‘scaffold.list.thtml’ (or in v0.10: ‘scaffold_index.thtml’) in the /app/views/posts/ folder you made earlier. The fastest way to get this done is to copy the file /cake/libs/view/templates/scaffolds/list.thtml. Next you can start customizing this view, without needing to modify controller code.


If the scaffold controller action is not sufficient then you need to:


2) provide an action and :action:.thtml template


You’ll create a function in the controller for the view you want to override as well as a a file in the view folder for that controller.


For example, to override the ‘index’ view, create a file called ‘index.thtml’ in the /app/views/posts/ folder you made earlier. The fastest way to get started with a new view is to copy the HTML from the view generated when using scaffolding. To do that, view the source for the index page in your browser of choice, copy the code between the opening content div (<div id=”content”>) and the closing content div (</div>). Paste that into your new ‘index.thtml’ file and you’ll have the basics there to work with rather than starting from scratch.


Next, you’ll need to change your Posts Controller? (/app/controllers/posts_controller.php) include the ‘index’ function:


class Posts Controller? extends App Controller?
{
var $name = 'Posts';
var $scaffold; // leave this here so Cake can scaffold the other views that are not overridden
function index() {
}
}

Adding the ‘index’ function to the Posts Controller? will keep scaffolding from attempting to do the work for you and will look for an ‘index.thtml’ file instead.

No hay archivos en esta página. [Enseñar archivos/formulario]
No hay comentarios en esta pagina. [Enseñar comentarios/formulario]