Skip to content

Instantly share code, notes, and snippets.

View violetyk's full-sized avatar

kagaya violetyk

View GitHub Profile
@violetyk
violetyk / admin_login.ctp
Created October 10, 2011 09:52
$session->flash()
<?php
// CakePHP 1.3からflashは戻り値が返るので、自前でechoする
if ($session->check('Message.auth')) echo $session->flash('auth');
@violetyk
violetyk / staffs_controller.php
Created October 11, 2011 03:20
[cakephp]コントローラに設定するpainate
<?php
var $paginate = array(
'Staff' => array(
'fields' => array('Staff.id', 'Staff.email', 'Staff.staff_name', 'Staff.status'),
'limit' => 10,
'order' => array('Staff.id' => 'desc'),
'conditions' => array(
'Staff.status >= ?' => array( 1 ),
),
'recursive' => -1,
@violetyk
violetyk / app_model.php
Created October 17, 2011 09:59
[cakephp]パスワード確認入力のバリデーション
<?php
class AppModel extends Model {
function equaltofield($check,$otherfield) {
$fname = '';
foreach ($check as $key => $value){
$fname = $key;
break;
}
@violetyk
violetyk / gist:1292344
Created October 17, 2011 10:22
[cakephp]1項目に複数のバリデーション
<?php
'password_tmp' => array(
'alphanumeric' => array(
'rule' => 'alphaNumeric',
'message' => '半角英数字で入力して下さい。',
),
'minlength' => array(
'rule' => array('minLength', 8),
'message' => '8文字以上で入力して下さい。',
)
@violetyk
violetyk / paging.ctp
Created October 18, 2011 03:31
[cakephp]TwitterBootstrap対応、ページングエレメント
<p><?php echo $paginator->counter(array('format' => '全 %count% 件中 %start% 件 から %end% 件を表示')); ?></p>
<!-- pagination -->
<?php if (isset($paginator) && $paginator->hasPage(null, 2)): ?>
<div class="pagination">
<ul>
<?php if ($paginator->hasPrev()): ?>
<li class="prev"><?php e($paginator->first('« 最初', array())); ?></li>
<?php e($paginator->prev('< 前へ', array('tag' => 'li'))); ?>
<?php else: ?>
<li class="prev disabled"><a href="#">« 最初</a></li>
@violetyk
violetyk / contents_controller.php
Created November 11, 2011 10:01
[cakephp]Matchablebehaviorを使ってHABTMのpaginate
<?php
$this->paginate['Content'] = array(
'jointo' => array(
'Tag',
),
'conditions' => array(
'Tag.id' => array(1,2)
),
'group' => 'Content.id',
@violetyk
violetyk / category.php
Created November 16, 2011 12:42
[cakephp]treeviewを作るサンプル1/3(モデル)
<?php
//モデル
function generateCategoryTree($id=0, $column_id='id', $column_name='name') {
$tree = array();
if($id == 0) {
$children = $this->find(
'all',
array(
@violetyk
violetyk / gist:1369994
Created November 16, 2011 12:45
[cakephp]treeviewを作るサンプル2/3(コントローラ)
<?php
$this->set('category_tree', $this->Category->generateCategoryTree());
@violetyk
violetyk / admin_add.ctp
Created November 16, 2011 12:49
[cakephp]treeviewを作るサンプル3/3(ビュー)
<div class="clearfix">
<label for="">階層から選ぶ</label>
<div class="input">
<div id="sidetreecontrol"> <a href="?#">全て閉じる</a> | <a href="?#">全て開く</a> </div>
<ul id="category_tree" class="treeview">
<?php
function expand($tree) {
$html = '';
foreach($tree as $id => $name) {
@violetyk
violetyk / contents_controller.php
Created November 17, 2011 07:46
[cakephp]ScheduleBehaviorでまだできないこと
<?php
// 今のところエディット時にパースして日付と時間をわけないとだめ。
if (empty($this->data)) {
$this->Content->Behaviors->detach('Schedule');
$this->data = $this->Content->read(null, $id);
$published = date_create($this->data['Content']['published']);
if($published != null) {
$this->data['Content']['published_date'] = date_format($published, 'Y-m-d');
$this->data['Content']['published_time'] = date_format($published, 'H:i:s');