Ethnaアクション名の決定方法を変更

Twitter ツイート Hatena Bookmark ブックマーク

アクション名がデフォルトだといろいろと使いづらいですよ。
単純にURLがかっこ悪いってものあるけど。
なので、変更します。
僕はよくactパラメータにアクション名を渡すって方法をつかっています。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
http://xxxx.jp/act=index```

見たいな感じで。

変更方法は「<a title="アクション名の決定方法を変更する" href="http://ethna.jp/ethna-document-dev_guide-action-formname.html" target="_blank">アクション名の決定方法を変更する</a>」ここに記載されています。

しかーし、これだけだとフォームヘルパーが上手く動かなくなってしまう。確かね…  
そこでほgetActionRequestメソッドの変更をします。

・appid_Controller.php

function getActionRequest($action, $type = “hidden”) {  $s = null;

 if ($type == “hidden”) {    $s = sprintf(’’,                   htmlspecialchars($action, ENT_QUOTES));  } else if ($type == “url”) {  $s = sprintf(‘act=%s’, urlencode($action));  }

 return $s; }```

actにしたい場合は、hiddenのnameの値をactする。
それだけでフォームヘルパーも問題なくつかえてしまう。

全体としてはこんな感じで

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//アクション名の設定変更
function _getActionName_Form()
{
 if (array_key_exists('act', $_REQUEST) == false) {
  return null;
 }
 return $_REQUEST['act'];
}

//フォームヘルパーのために
function getActionRequest($action, $type = "hidden")
{
 $s = null;
 if ($type == "hidden") {
  $s = sprintf('<input type="hidden" name="act" value="%s">',
                htmlspecialchars($action, ENT_QUOTES));
 } else if ($type == "url") {
  $s = sprintf('act=%s', urlencode($action));
 }
 return $s;
}```

こんな感じで書けばアクション名の指定は変更できます。  
やっぱデフォルトだとかっこわるいからね・・・
comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。