Skip to content

Instantly share code, notes, and snippets.

View erikfig's full-sized avatar
🏠
Working from home

Erik Figueiredo erikfig

🏠
Working from home
View GitHub Profile
@erikfig
erikfig / MyModel.php
Created May 2, 2014 13:16
How to change status in cakephp - Como trocar status no CakePHP
<?php
class MyModel extends AppModel
{
/*
* Change MyModel to your Model
* Change status to your field in database
* $id is your primary key to registry in database
*
@erikfig
erikfig / gist:d03e29c1ee60ffe1506a
Created May 2, 2014 13:26
CakePHP Hashs Generator (Security.salt e Security.cipherSeed) - Gerador de Hashs (Security.salt e Security.cipherSeed) para CakePHP
<html>
<head>
<title>CakePHP Gerador de Hash</title>
</head>
<body>
<h1>Gerador de Hash Para CakePHP</h1>
<p>Recarregue a p&aacute;gina para gerar novos hashs!</p>
<?php
function geraSenha($tamanho = 15, $minusculas = true, $maiusculas = true, $numeros = true, $simbolos = true)
{
<?php
App::uses('Security', 'Utility');
class UsuariosController extends AppController {
function beforeFilter(){
parent::beforeFilter();
if ($this->action == 'admin_login'){
$this->action = 'login';
}
$this->Auth->allow(array('admin_add'));
<?php
App::uses('Security', 'Utility');
class UsuariosController extends AppController {
function beforeFilter(){
parent::beforeFilter();
if ($this->action == 'admin_login'){
$this->action = 'login';
}
$this->Auth->allow();
@erikfig
erikfig / index.php
Created March 25, 2015 13:59
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
@erikfig
erikfig / gist:5c2481e493f72011f8fb
Created May 20, 2015 23:07
Instalar PHP mais rescente no Ubuntu
sudo add-apt-repository ppa:ondrej/php5-5.6
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install php5
@erikfig
erikfig / gist:6328c284f48f03972578
Created May 26, 2015 00:04
CakePHP 3 Auth personalizado
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'loginAction' => [
'controller' => 'Usuarios', //aqui eu troco o controller
'action' => 'acesso' //aqui a action que vamos usar pra logar
],
'authenticate' => [
'Form' => [
@erikfig
erikfig / gist:a14fe5ad44bd511e62e6
Created May 27, 2015 21:33
schema.php - Como criar um CMS com CakePHP 2
<?php
App::uses('Seo', 'Model');
App::uses('Pagina', 'Model');
class AppSchema extends CakeSchema {
public function before($event = array()) {
$db = ConnectionManager::getDataSource('default');
$db->cacheSources = false;
return true;
}
@erikfig
erikfig / gist:2be495fa1f104582fd51
Created May 27, 2015 21:38
Sql - Como criar um CMS com CakePHP 2
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `paginas`;
CREATE TABLE `paginas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`menu` varchar(512) DEFAULT NULL,
`corpo` text,
@erikfig
erikfig / gist:7c5e5a65fd5b1fdef42a
Created June 3, 2015 14:50
CakePHP 3 proibir acesso a administração
public function beforeFilter(Event $event)
{
$user = $this->Auth->user();
$params = $this->request->params;
if ($user['admin'] != 1 and isset($params['prefix']) and $params['prefix'] == 'admin')
throw new ForbiddenException('Você não tem permissão');
}