Crear un panel de administración con layout personalizado con CakePHP

¿Quieres un panel de administración separado en tu aplicación CakePHP? Para crear uno necesitaremos editar algunos ficheros y crear algunos nuevos. También crearemos un theme para el panel de administración, y lo utilizaremos cuando entremos como administradores.

Usaremos CakePHP 2.x para este tutorial.

1. Edita /app/Config/core.php

1
2
3
4
Encuentra:
Configure::write('Routing.prefixes', array('admin'));
Añadimos el prefijo admin y lo descomentamos.

2.  Crea un layout para admin

– ve a /app/View/Layouts
– haz una copia de default.ctp y renómbrala como admin.ctp

3. Edita el layout admin.ctp

– haz las modificaciones necesarias al layout

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Ejemplo:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
    <?php echo $this->Html->charset(); ?>
    <title>Administrator | <?php echo $title_for_layout; ?></title>
    <?php
        echo $this->fetch('meta');
        echo $this->Html->css(array('admin'));
        echo $this->fetch('css');
        echo $this->fetch('script');
    ?>
</head>
<body>
    <div id="container">
        <div id="header">
            <div class="logo"></div>
            <div class="clear"></div>
        </div>
        <div id="content-wrapper">
            <?php echo $this->fetch('content'); ?>
        </div>
        <div id="footer">
            © <?php echo date("Y");?> - All rights         
    </div>
             <?php echo $this->element('sql_dump'); ?>   
    </div>
</body>
</html>

4. Crea la hoja de estilos admin.css

– /app/webroot/css/admin.css
– añade los estilos que desees

5. Edita AppController.php

– Añade la comprobación de prefijo en tu función beforeFilter para cargar tu layout admin

1
2
3
4
5
public function beforeFilter() {
    if ((isset($this->params['prefix']) && ($this->params['prefix'] == 'admin'))) {
        $this->layout = 'admin';
    }
}

6. Edit UsersController.php

– We need to tell UsersController that it needs to run the beforeFilter from AppController (remember to put this in all your controllers).

1
2
3
4
public function beforeFilter() {   
    parent::beforeFilter();
    // Controller spesific beforeFilter
}

– Crea una función de administración:

1
2
3
4
public function admin_dashboard() {
        $title_for_layout = 'Dashbord';
        $this->set(compact('title_for_layout'));
    }

– Crea la vista para la función (/app/Views/Users/admin_dashboard.ctp)

1
2
<h1>Dashboard</h1>
<p>Bienvenido al Panel de Administración</p>

7. Apunta el navegador a la localización de tu admin
– Si tienes funciones de login y Auth en juego, intenta establecer los permisos de autentificación a * en UsersController.php

1
$this->Auth->allow('*');

– Ve a: your-domain.com/admin/users/dashboard
– Tu nuevo layout de administración debería renderizarse ahora, y deberías ver el mensaje “Bienvenido al Panel de Administración”.

8. Crea más funciones + Controllers + Views + Models
– Recuerda poner admin_ en todas las funciones/views de administración
– Cuando se usa el prefijo “admin_”, se renderizará el layout admin.

Anuncios

Borrar directorios .svn recursivamente

Habiéndo cambiado a git ya no eran necesarios los directorios .svn que plagaban mis proyectos. Así que me puse a de buscar una forma de borrarlos rápidamente:

rm -rf `find . -type d -name .svn`

La primera parte del comando [ rm – rf ] es para borrar, la segunda [ find . -type d -name .svn ] es el predicado a eliminar: todos los archivos/directorios de nombre .svn dentro del directorio actual.

Otras formas de hacerlo:

find . -type d -name '.svn' -print0 | xargs -0 rm -rdf 
find . -name .svn -print0 | xargs -0 rm -rf
find . -name .svn -exec 'rm -rf {};'

Referencias

Recursively delete .svn directories
Unix Command To Remove Subversion .svn Directories
Recursively remove all .svn directories

02. Instalar Zend Server CE 5.6.0 en Ubuntu 12.10

En el momento de la redacción de este artículo (27/11/2012), la versión actual descargable de Zend Server es la 5.6.0 SP4 (válida para PHP 5.2 y 5.3).

Para instalarso seguiremos los siguientes pasos:

1. Descargamos el script de instalación (disponible en RPM/DEB) desde el sitio oficial de Zend.

2. Accedemos al directorio creado tras descomprimirlo. Dependiendo de si queremos instalar Zend Server con soporte para PHP 5.2 o 5.3 ejecutaremos:

– Para PHP 5.2: # sudo ./install_zs.sh 5.2 ce
– Para PHP 5.3: # sudo ./install_zs.sh 5.3 ce

Una vez finalice la instalación podemos ingresar vía web al panel de administración de Zend Server, desde las siguientes URLs:

– Modo seguro: https://localhost:10082/ZendServer/
– Modo normal: http://localhost:10081/ZendServer/

01. Comenzando a desarrollar con Android

If you are interested in developing applications for Android, then the first thing you’ll need to know is what tools will be required to create your applications and publish them on the Android Market. Below is a quick list with links to getting you started. Best of all, they are all free…

  • Android SDK

You’ll need to start by downloading the Android SDK (Software Development Kit):

Download the Android SDK

  • Eclipse IDE

The Eclipse IDE (Integrated Development Environment) is the preferred environment as the tools needed to create, build, test, and deploy are easily invoked from within the IDE. The Eclipse Classic version is the recommended IDE (Eclipse IDE for Java Developers):

Eclipse Downloads

  • ADT Plugin for Eclipse

The ADT plugin extends the capabilities of Eclipse. It provides an integrated environment from which to build Android application:

Installing the Android ADT plugin for Eclipse

  • SQLite Database Browser

If your application requires a data storage mechanism, Android includes support for SQLite. If you need to create, edit, or view the contents of the database, the SQLite database browser is for you:

Download SQLite Data Browser from SourceForge.net

  • Graphics Editor

For graphics development such as icons, buttons, backgrounds, etc., try Inkscape, a free vector graphics editor.

Download InkscapeOfficial Release Packages

A good place to start: Inkscape Tutorial -Shiny Button

  • Version Control System (VCS)

As you develop your application, you will no doubt need to keep track of the changes that you make in the code. One VCS to consider is EGit, an Eclipse Team provider for the Git version control system. EGit is installed through the Eclipse IDE, see the following links for details:

Install the Latest Version of EGit

[FFMPEG] Conversión de AVCHD a MP4/H264/AAC con FFMPEG

I have a Canon HF200 HD video camera, which records to AVCHD format. AVCHD is H.264 encoded video and AC-3 encoded audio in a MPEG-2 Transport Stream (m2ts, mts) container. This format is not supported by Aperture 3, which I use to store my video.

With Blizzard’s help, I figured out an ffmpeg command-line to convert to H.264 encoded video and AAC encoded audio in an MPEG-4 (mp4) container. This is supported by Aperture 3 and other Quicktime apps.

$ ffmpeg -sameq -ab 256k -i input-file.m2ts -s hd1080 output-file.mp4 -acodec aac

Command-line order is important, which is infuriating. If you move the -s or -ab arguments, they may not work. Add -deinterlace if the source videos are interlaced, which mine were originally until I turned it off. The only downside to this is that it generates huge output files, on the order of 4-5x greater than the input file.

Update, 28 April 2010: Alexander Wauck emailed me to say that re-encoding the video isn’t necessary, and that the existing H.264 video could be moved from the m2ts container to the mp4 container with a command-line like this:

$ ffmpeg -i input-file.m2ts -ab 256k -vcodec copy -acodec aac output-file.mp4

And he’s right… as long as you don’t need to deinterlace the video. With the whatever-random-ffmpeg-trunk checkout I have, adding -deinterlace to the command-line segfaults. I actually had tried -vcodec copy early in my experiments but abandoned it after I found that it didn’t deinterlace. I had forgotten to try it again after I moved past my older interlaced videos. Thanks Alex!

[PHP] Librerías de Manipulación de Imágenes para PHP

Librerías de Manipulación de Imágenes para PHP

Otras librerías de manipulación de imágenes (y lenguajes que soportan directamente):

Ver también:


I’m designing a website and I need to:

  • Upload the image
  • Validate that it’s an image (and not, oh I don’t know…. a virus 🙂 )
  • Resize the Image
  • convert to jpg

Essentially basic image upload

Instead of writing my own I’m trying to find a php class that let’s me do all this, because as Jeff Atwood said, “never design what you can steal”

Now before you go ahead and downvote because I didn’t do my research, I did:

Googling this brings up a huge amount of results, which is the problem, I don’t know which results are useful and which are trash!

So far, Ive found:

Does anyone have any experience with these classes? Can you recommend an outstanding image upload class?

If you want to make the uploader a tiny bit better than just an input type=file, try:

https://github.com/valums/file-uploader

http://www.verot.net/php_class_upload.htm

: Python