Posts Tagged ‘PHP’
MacportでPHPをインストールし、CakePHPを動かしたら「Strict Standards」エラーが出ました。
当時のエラー本文は残ってませんので、Googleで検索したエラー本文を貼り付けます。パス以外は同じのはずです。
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/basics.php on line 279
Strict Standards: Redefining already defined constructor for class Object in /Applications/MAMP/htdocs/xxxx/cake/libs/object.php on line 65
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/object.php on line 92
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/inflector.php on line 65
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/configure.php on line 96
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/configure.php on line 154
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/cache.php on line 71
Strict Standards: Assigning the return value of new by reference is deprecated in /Applications/MAMP/htdocs/xxxx/cake/libs/cache.php on line 157
Strict Standards: Non-static method Configure::getInstance() should not be called statically in /Applications/MAMP/htdocs/xxxx/cake/bootstrap.php on li
これはCakePHPの問題ではなく、PHPのerror_reportingの設定問題だそうです。
php.iniを開いてerror_reportingで検索します。
値をE_ALLに変更すれば解決です。
ちなみにMacportでPHPをインストールしたときのphp.iniパスは/opt/local/etc/php5/php.iniになります。
http://oldblog.awpny.com/2007/12/mamp-php5-cakephp-and-strict-standards/
Tags: cakephp, macport, PHP, 環境構築
Posted in PHP5 | No Comments »
2011年03月07日
file_get_contentsとjson_decodeの組み合わせでAPIコールするサンプルコードです。
// APIコール
$api_url = 'http://example.com/api/';
$api_ret = file_get_contents($api_url);
// JSONにデコード
$api_result = json_decode($api_ret,true);
// APIエラーチェック: 何かしらの成功フラグでチェック
if(isset($api_result['success']) && $api_result['success'] == 0)
{
// 処理
}
else
{
// handle error
}
Tags: API, PHP, Snippet
Posted in PHP5 | No Comments »
2011年02月18日
Oracle Instantclientをインストールすることで、PHPからOracleデータベースへの接続が可能になります。
XAMPPのデフォルトインストールではそれが無効となっています。確認方法はphpinfoのページから’oci8′を検索して何もなかったらつまり接続できてないことです。
- php.ini(XAMPP/phpのパスにある)の中から;extension=php_oci8.dllを検索して、セミコロン(;)を削除。
- Oracleから“Instant Client Package – Basic” for Windowsをダウンロードし、任意の場所に解凍。ここではc:\instantclient_11_1とする。
- Windowsの環境変数pathに上記instantclientが解凍されたパスを追加(c:\instantclient_11_1)
- そしてWindowsを再起動!
- Apacheを再起動
phpinfoのページからoci8を検索してあれば成功!
- ORACLE_HOMEやORACLE_SIDなどの環境変数はInstant Clientでは必要ないから設定しなくても大丈夫だそう。
- パス設定後Windowsを再起動しないと、”unable to load dynamic library php_oci8.dll”のようなエラーが出た。
Tags: oracle, PHP, XAMPP, 環境構築
Posted in PHP5 | No Comments »
2011年02月03日
$this->Ingredient->save($newData);
$newIngredientId = $this->Ingredient->id; // OK
// id以外のフィールドはダメ
$this->Ingredient->name; // NG
$this->Ingredient->category; // NG
登録/更新には関係なく。
公式マニュアルでは:
一度保存が完了してしまうと、オブジェクトの ID をモデルオブジェクトの $id プロパティで取得することができます。特に新しいオブジェクトを生成した場合に便利です。
http://book.cakephp.org/ja/view/75/データを保存する
と書いてありますが、id以外のフィールド情報は持ってないようです。
欲しければ$this->dataから取れます。
Tags: cakephp, model, orm, PHP
Posted in PHP5 | No Comments »
2011年02月01日
/**
* 文字列を全て半角に
* @param string $str 文字列
* @return string $str 半角の文字列
*/
function toHankaku($str) {
$str= mb_convert_kana($str,"rnask");
return $str;
}
Tags: PHP, string
Posted in PHP5 | No Comments »
2010年12月27日
$_GET、 $_POST そして $_COOKIE の内容をまとめた連想配列です。
もう少し説明を加えると、
In the beginning of execution, $_REQUEST is a clone of $_GET. $_POST is then merged into the array, overwriting keys if they exist in both $_GET and $_POST. Finally, $_COOKIE is merged into the array, again overwriting old values.
まずは$_GETのクローンでそこに$_POSTをマージする感じで、同じキーのものがあれば上書きされます。同じくその後$_COOKIEもマージします。
なので本当にPOSTで受取るものは$_REQUESTに書き換えてはいけないと思いますね。
Tags: PHP
Posted in PHP5 | No Comments »
2010年11月26日
XAMPP1.7.3 + WinXP
ダウンロードはこちら
- http://code.jellycan.com/memcached/よりmemcached 1.2.6 => win32 binaryバージョンのファイルをダウンロード
- zipファイルを適当な場所(例えばc:\memcached)に解凍
- コマンドプロンプトから下記コマンドを叩く、Windowsサービスとしてインストール。これで今度Windowsが起動すると自動でmemcacheサーバが起動してくれる。
c:\memcached.exe -d install
コマンドプロンプト
c:\memcached\memcached.exe -d start
XAMPPのパス/php/php.iniを編集:下記コードを追加
extension = php_memcache.dll
ここはLinux環境と違い拡張子が.soではなく.dll。
http://downloads.php.net/pierre/から’memcache’を検索して正しいバージョンのファイルをダウンロード。
そしてxampp/php/extに入れる。
ここで問題!正しいバージョンはなんなのか?間違ってダウンロードすると後でApacheサーバを立ち上がるときエラーが出るよ。私の環境だとphp_memcache-cvs-20090703-5.3-VC6-x86.zipのファイルが正しいけど、今時点で上記URLには載せていない。結構ググって見ても結局古い結果で、しょうがなく友人からそのファイル貰った。。。ここにアップしたので、必要な方はダウンロードしてください。ウイルススキャンしてね。。
php_memcache-cvs-20090703-5.3-VC6-x86
xamppでapacheサーバを起動、下記内容をphpファイルと保存してサーバのDocumentパス(デフォルトではXAMPP/htdocs)に置く。
connect("localhost",11211); // try 127.0.0.1 instead of localhost
// if it is not working
echo "Server's version: " . $memcache->getVersion() . "\n";
// we will create an array which will be stored in cache serialized
$testArray = array('horse', 'cow', 'pig');
$tmp = serialize($testArray);
$memcache->add("key", $tmp, 30);
echo "Data from the cache:\n";
print_r(unserialize($memcache->get("key")));
?>
Memcached, by default, loads with 64mb of memory for it’s use which is low for most applications. To change this to something else, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached Server in your registry, find the ImagePath entry and change it to look something like this:
“C:\memcached\memcached.exe” -d runservice -m 512
http://www.codeforest.net/how-to-install-memcached-on-windows-machine
http://pureform.wordpress.com/2008/01/10/installing-memcache-on-windows-for-php/
Tags: Apache, memcache, PHP
Posted in Apache, PHP5 | No Comments »
2010年09月25日
application/viewsにhello.tplというファイルを作成します。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{$title}</title>
</head>
<body>
hello, {$name}
</body>
</html>
hello.phpというControllerを作成します。
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Hello extends Controller {
public function action_index()
{
$view = View::factory("smarty:hello");
$view->name = "kinopyo!";
$view->title = "Smarty & Kohana Sample";
$this->request->response = $view;
}
}
View::factoryに”smarty:”というプリフィックスを書くことでSmartyテンプレートとして認識してくれます。
http://127.0.0.1/myapp/helloにアクセスし、”hello, kinopyo!”が表示されれば成功です。
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Hello extends Controller_Template {
public $template = 'smarty:hello';
public function action_index()
{
$this->template->name = 'kinopyo!';
$this->template->title = "Hello Title";
}
}
Tags: kohana, PHP, Smarty
Posted in PHP5, Smarty | No Comments »