Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Erik Figueiredo erikfig

🏠
Working from home
View GitHub Profile
@erikfig
erikfig / MyModel.php
Created May 2, 2014
How to change status in cakephp - Como trocar status no CakePHP
View MyModel.php
<?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
CakePHP Hashs Generator (Security.salt e Security.cipherSeed) - Gerador de Hashs (Security.salt e Security.cipherSeed) para CakePHP
View gist:d03e29c1ee60ffe1506a
<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)
{
View gist:17e51552901eef089317
<?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'));
View gist:786b2b3adbed8596d9f2
<?php
App::uses('Security', 'Utility');
class UsuariosController extends AppController {
function beforeFilter(){
parent::beforeFilter();
if ($this->action == 'admin_login'){
$this->action = 'login';
}
$this->Auth->allow();
View index.php
<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
Instalar PHP mais rescente no Ubuntu
View gist:5c2481e493f72011f8fb
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
CakePHP 3 Auth personalizado
View gist:6328c284f48f03972578
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
schema.php - Como criar um CMS com CakePHP 2
View gist:a14fe5ad44bd511e62e6
<?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
Sql - Como criar um CMS com CakePHP 2
View gist:2be495fa1f104582fd51
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 Jun 3, 2015
CakePHP 3 proibir acesso a administração
View gist:7c5e5a65fd5b1fdef42a
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');
}