Help us understand the problem. What is going on with this article?

cakephp 2.x いろいろ

More than 1 year has passed since last update.

自分がよく使う書き方を残しておきます。

1.エラーレポーティング0
cakephp上ではエラーはでないけど、phpエラーが発生してしまう場合には書く。
基本的にはpublic function index() {などのすぐ真下に書いてます。

Controller.php
error_reporting(0);

2.検索条件「期間設定」
これが複雑で結構めんどい機能。もっと簡単な方法があればいいな。

Controller.php
// 期間指定
if(!empty($_GET['date_before']) && !empty($_GET['date_after'])){
  $option['conditions']['Orders.order_date BETWEEN ? AND ?'] = array($_GET['date_before']." 00:00:00", $_GET['date_after']." 23:59:59"); 
  $getform['date_before'] = $_GET['date_before'];
  $getform['date_after'] = $_GET['date_after'];
}elseif(!empty($_GET['date_before']) && empty($_GET['date_after'])){
  $option['conditions']['Orders.order_date >='] = $_GET['date_before']." 00:00:00";
  $getform['date_before'] = $_GET['date_before'];
}elseif(empty($_GET['date_before']) && !empty($_GET['date_after'])){
  $option['conditions']['Orders.order_date <='] = $_GET['date_after']." 00:00:00";
  $getform['date_after'] = $_GET['date_after'];
}

3.検索条件「フリーワード」
こんな感じ

Controller.php
// フリーワード
if(!empty($_GET['keyword'])){
  $keys = preg_split('/[\s|\x{3000}]+/u', $_GET['keyword']);
  foreach($keys as $key => $value){
    $option['conditions'][$key]['OR']['Orders.order_no like'] = "%".$value."%";
    $option['conditions'][$key]['OR']['Orders.campany_name like'] = "%".$value."%";
    $option['conditions'][$key]['OR']['Orders.order_name_sei like'] = "%".$value."%";
    $option['conditions'][$key]['OR']['Orders.order_name_mei like'] = "%".$value."%";
}

4.アップデート後とかにリダイレクト

Controller.php
header('Location:'.$_SERVER['HTTP_REFERER']);
exit;
Youz
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした