php フォーム内の改行を表示させる
フォームに入力した内容をそのまま表示させたいが、
改行は表示させた時に、改行がない状態で表示されるため、そのまま表示させるための
記述が必要になる。
<?php echo nl2br(h($test['Test']['comment']));?>
頭にこれ nl2br () 関数つけるだけで自動的に処理してくれます。
楽だな〜〜
【Cakephp】ページャー
基本的ないつも入れいているページャーが動かないため、
別の方法で実装しました。
普段は、public として設定するのですが、
これで動かないためfunction内に記述する方法を使いました。
public function index() {
$this->paginate=array(
'limit'=>5,
'direction'=>'asc',
);
$this->foo->recursive = 0;
$this->set('foos', $this->Paginator->paginate());
}
これだけ。。。。
メモのために保存。
書いていても、書いていることを忘れてまた検索する〜調べる〜ない〜
あ!はてなに書いていたかも!
と思い出す。意外にある。。www
時間の無駄。
cakephp 日付で検索
こちらのサイトを参考にさせていただきました。
ありがとうございます。
ほぼそのままでイケました!!!!
http://kamakurasoft.net/blog/?p=1479
しかし、なにかよくわからい棒線がselectboxの横にできるのはなぜ??
コード見てもどこに記述されているか不明だわ〜〜
棒なに??
model
View
controller
<?php
class PostsController extends AppController{
public $uses = array('Post','Comment');
public $helpers = array('Html','Form');
public $components = array('Search.Prg');
public $presetVars = true;
// public $presetVars = array(
// array('field'=>'title','type'=>'value'),
// array('field'=>'body','type'=>'value'),
// array('field'=>'end','type'=>'checkbox'),
// array('field'=>'start','type'=>'checkbox'),
// );
public function index(){
//
$this->Prg->commonProcess();
$conditions = $this->Post->parseCriteria($this->passedArgs);
$this->paginate = array(
'limit'=>10,
//'order'=>array('id'=>'desc'),
'conditions'=>$conditions,
);
$this->set('posts',$this->paginate());
}
}
cakephp オートコンプリート機能 (DBからデータ取得)
TestAAAのページからTestBBBのデータベースの値を取得して、
オートコンプリート機能を実装。
まずは、Viewを作成
1.フォームの追加
<?php echo $this->Form->input('name', array(
'type' => 'text',
'id' => 'autocomplete',
)); ?>
2.Javascriptの読み込み
<script type="text/javascript">
$(function(){
$('#autocomplete').autocomplete({
source: 'http://localhost/cakephp/testAAA/autocomplete',
autoFocus: true,
//delay: 500,
//minLength: 2
});
})
</script>
下記のURLから値を拾う!
http://localhost/cakephp/testAAA/autocomplete
3.コントローラーの作成
上記のURLにjsonで値を渡す。
public function autocomplete(){
$this->loadModel('testBBB');
$field = 'name';
$term = $this->params['url']['term'];
// 入力値 無:全てのデータの中から10件返す。
// 入力値 有:入力値を含むデータを10件返す
$condition = array();
if(!empty($term)){
$condition = array('testBBB.'.$field.' like' => "%".$term."%");
}
$query = array(
'fields' => array($field),
'conditions' => $condition,
'limit' => 10,
'order' => array('testBBB.'.$field => 'ASC'),
'group' => $field,
);
$data = array();
$items = $this->testBBB->find('all', $query);
foreach ($items as $item) {
$cnt = array_push($data, $item['testBBB'][$field]);
}
// JSONデータのみを返す
$this->viewClass = 'Json';
$this->set(compact('data'));
$this->set('_serialize', 'data');
}
これでいけた!!!!!
3日間もハマってました。。。笑
【css】上下中央揃え
.parent{ height: 200px; display: table-cell; vertical-align: middle; }