2017年2月22日水曜日

setcookieした内容がリダイレクトで消える件

セットしたクッキーがリダイレクト後に消えてしまう
setcookie( "test", "value", time() + 1800 );
header("location:example.com");
デフォルトではカレントディレクトリが有効範囲らしいので
setcookie( "test", "value", time() + 1800, "/" );
としてドメイン配下をすべて有効にするとうまくクッキーが焼けました

2017年2月13日月曜日

今更ながらgitのお勉強(1) 基本のコマンド

よく使うgitの基本コマンドをまとめました。

git init
プロジェクトをgitで管理するときに使用する
git init

git add
新規追加された、更新されたファイルをaddする
git add . (カレントディレクトリ以下のファイルをすべてaddする)
git add -u (既にgit管理内にあるファイルのみで、変更があった部分のみをaddする)

git commit
addされたファイルをコミットする
git commit -a (変更のあったファイルをすべてコミット)
git commit -v (変更点を表示してコミット)
git commit -m (コメントを残してコミット)
git clone
既存のリポジトリからコピーしたいときに使う
git clone ○○○(http://~~, ssh://~~)

git pull
リポジトリの最新情報を取得し(fetch)現在の状態とマージ(merge)する
git pull origin master (originリポジトリのmasterブランチからpullする)

git push
リポジトリへ更新をプッシュする
git push origin master (originリポジトリのmasterブランチにpushする) 

2015年2月18日水曜日

メソッドのオーバーライド時のエラーを回避する

とあるメソッドをオーバーライドしたとき

Declaration of %s::%s() should be compatible with that of %s::%s()

というエラーが発生しました。

これは親クラスのメソッドと引数が異なるのが原因でした。
http://www.1x1.jp/blog/2007/11/php_e_strict_message.html

しかし
親クラス
public function getUserInfo( $a ){

子クラス
public function getUserInfo( $a, $b = NULL, $c = NULL ){

のようにデフォルト値を持つ引数は追加できるのでこの方法で回避できます。

2015年2月16日月曜日

Ajax通信のsuccess時に自身の関数に返す処理


successに自身の関数を呼び出せばいいようです。

//コールバック
function result_test_callback(result){

  $('#result_site_patrol_message_member').html(result);

  $('input:button[name=shuffle_message_member]').click(function(){

    if (confirm('再抽選を実行してよろしいですか?')) {

      if(xhr_shuffle){
        xhr_shuffle.abort();
      }

      xhr_shuffle = $.ajax({
        url  : url,
        type : "post",
        processData : false,
        data : post_data,
        dataType : "json",
        async : false,
        cache : false,
        success : result_test_callback ←これ 
            });

   }
 });

}

2014年10月29日水曜日

jQueryのunrecognized expressionについて

とあるファイルの操作で

Uncaught Error: Syntax error, unrecognized expression: 
input:hidden[name*=images[20141029_181853_4552483cf23a5f224d54e0aa79241a14]] 

というエラーが発生しました。
input:hidden[name*='images[20141029_181853_4552483cf23a5f224d54e0aa79241a14]']

のようにシングルクオテーションでくくれば直りました。
内側と外側の引用符(記号)が同じだとエラーになるようです。

つまり、

$('input[name='text']');

のようなパターンもダメ。

2014年8月22日金曜日

FlexモバイルプロジェクトでHTMLを表示する方法

前回まではFlush CCを使っていましたが、画面遷移とかスプラッシュ画面とかが面倒なのでFlash CCでの開発はやめて、FlashBuilderを使うことにしました。

今回はFlash上にHTMLを表示する方法について。

<mx:HTML>を使おうとするとエラー
→Flexモバイルでは使えない?
http://help.adobe.com/ja_JP/flex/mobileapps/WSf3db6597adcd110e19124fcb12ab3a1c319-8000.html#WS8b1c39bd7e9fc3643c4a6fa12a8ac8b916-8000

stageWebViewを使うとモバイルアプリケーション内でブラウジング機能を利用することができます。


<?xml version="1.0" encoding="utf-8"?>
<s:View 
xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
actionBarVisible="false" 
creationComplete="IframeHandler(event)" 
title="Map">

<fx:Script>
<![CDATA[
   //HTMLを読み込む
   protected function IframeHandler(event:FlexEvent):void
   {
    var webView:StageWebView = new StageWebView(); webView.viewPort = new Rectangle(0, 430, this.stage.stageWidth, this.stage.stageHeight);
webView.stage = this.stage;
    var htmlString:String = 
    "<!DOCTYPE HTML>" +
    "<html><body>" +
    "<p>てすとです</p>" +
    "</body></html>";
    webView.loadString(htmlString, "text/html");
   }
]]>
</fx:Script>
 (~中略~)
</s:View>

HTMLが表示されました。

2014年8月19日火曜日

ActionScript3.0とNode.jsでSocket通信をする

今回は、Node.jsとSocket通信でメッセージを送りたい場合のお話。

前回まではレイヤーに書いてましたが、今回はクラスにActionScriptを読み込みます。



















ソースは以下のとおり。

SocketEx.as

package
{
import flash.display.Sprite;
import flash.events.DataEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MouseEvent;
import flash.net.XMLSocket;

public class SocketEx extends Sprite
{
private var _xmlSocket:XMLSocket; //ソケット
 
 
// --------------------------------------
// コンストラクタ
// --------------------------------------
public function SocketEx()
{
// EVENTS
addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
 
}
 
// --------------------------------------
// メソッド
// --------------------------------------
//ステージの追加とソケットの接続
private function _onAddedToStage(aEvent : Event):void
{

_xmlSocket = new XMLSocket("153.127.250.224", 3000);
 
// EVENTS
stage.removeEventListener(MouseEvent.CLICK,         _onAddedToStage);
//
_xmlSocket.addEventListener(Event.CONNECT,          _onConnected);
_xmlSocket.addEventListener(IOErrorEvent.IO_ERROR,  _onIOError);
 
}
//ソケットの接続
private function _onConnected(aEvent : Event):void
{
//  TRACE
trace("onConnect() aEvent: " + aEvent);
 
//  EVENTS
_xmlSocket.removeEventListener(Event.CONNECT,           _onConnected);
_xmlSocket.removeEventListener(IOErrorEvent.IO_ERROR,   _onIOError);
//
_xmlSocket.addEventListener(DataEvent.DATA,             _onDataReceived);
_xmlSocket.addEventListener(Event.CLOSE,                _onSocketClose);

button_send.addEventListener(MouseEvent.CLICK, _onMessageSend);
 
}
 
//ソケットの切断
private function _onSocketClose(aEvent : Event):void
{
//  TRACE
trace("_onSocketClose aEvent : " + aEvent);
 
//  EVENTS
_xmlSocket.removeEventListener(Event.CLOSE, _onSocketClose);
_xmlSocket.removeEventListener(DataEvent.DATA, _onDataReceived);
}

//送信ボタンが押されたときの処理
private function _onMessageSend(evt:MouseEvent):void
{
_xmlSocket.send(message_send.text);
}
 
//送信データの受信
private function _onDataReceived(aEvent : DataEvent):void
{
try {
 
//  Show the server data in text
message_receive.htmlText += (aEvent.data + "\n");
 
//scroll down to show latest line
message_receive.scrollV = message_receive.maxScrollV;
 
} catch (error : Error) {
//  TRACE
trace("_onDataReceived error:  " + error);
}
}
 
//接続エラー
private function _onIOError(aEvent : IOErrorEvent):void
{
//  TRACE
trace("_onIOError aEvent: " + aEvent);
 
//  EVENTS
_xmlSocket.removeEventListener(Event.CONNECT, _onConnected);
_xmlSocket.removeEventListener(IOErrorEvent.IO_ERROR, _onIOError);
stage.addEventListener(MouseEvent.CLICK, _onAddedToStage);
}
 
}
}


Node.jsが入っていることが前提としてサーバー側のソースが以下の通り

app.js

// --------------------------------------
// Imports
// --------------------------------------
var net = require('net');
var mySocket;

// --------------------------------------
// Construct The Socket
// --------------------------------------
// create the server and register event listeners
var server = net.createServer(function(socket) {
    mySocket = socket;
    mySocket.on("connect", onConnect);
    mySocket.on("data", onData);
});

// --------------------------------------
// Events
// --------------------------------------
/**
 * Handles the Event: <code>"connect"</code>.
 *
*/
function onConnect()
{
    console.log("Connected to Flash");
}

/**
 * Handles the Event: <code>"data"</code>.
 *
 * When flash sends us data, this method will handle it
 *
*/
function onData(d)
{
    if(d == "exit\0")
    {
        console.log("exit");
        mySocket.end();
        server.close();
    }
    else
    {
        console.log("From Flash = " + d);
        mySocket.write(d, 'utf8');
    }
}

// --------------------------------------
// Start the Socket
// --------------------------------------
server.listen(3000, "IPアドレス");


実行
























という具合で動きました。