Yii ~ set baseUrl variable in every view, override render function



應該也有人很懶得打

Yii::app() -> request -> baseUrl;

整個就是又臭又長

所以我在Controller.php裡面放了這段

$this -> baseUrl = Yii::app() -> request -> baseUrl;

這樣要baseUrl的時候只要打$this->baseUrl

可是還是覺得很煩...........

因為我比較想打$baseUrl就好

可是這樣在每個view的檔案裏面就要加這段

$baseUrl =  Yii::app() -> request -> baseUrl;

麻煩死0rz

所以乾脆就複寫他原本的render function

讓他每次把data丟進去的時候順便把$baseUrl給設定進去


原本CController.php的render

public function render($view,$data=null,$return=false)
{
if($this->beforeRender($view))
{
$output=$this->renderPartial($view,$data,true);
if(($layoutFile=$this->getLayoutFile($this->layout))!==false)
$output=$this->renderFile($layoutFile,array('content'=>$output),true);

$this->afterRender($view,$output);

$output=$this->processOutput($output);

if($return)
return $output;
else
echo $output;
}
}


在Controller.php裡面加這段function去override

//override
public function render($view, $data = null, $return = false) {
if ($this -> beforeRender($view)) {

$data['baseUrl'] = Yii::app() -> baseUrl;

$output = $this -> renderPartial($view, $data, true);
if (($layoutFile = $this -> getLayoutFile($this -> layout)) !== false)
$output = $this -> renderFile($layoutFile, array('content' => $output), true);

$this -> afterRender($view, $output);

$output = $this -> processOutput($output);

if ($return)
return $output;
else
echo $output;
}
}


PHP ~ facebook publish stream


    $params = array(
                  'message'       =>  "Hurray! This works :)",
                  'name'          =>  "This is my title",
                  'caption'       =>  "My Caption",
                  'description'   =>  "Some Description...",
                  'link'          =>  "http://stackoverflow.com",
                  'picture'       =>  "http://i.imgur.com/VUBz8.png",
              );
    $post = $facebook->api("/$user/feed","POST",$params); 

in yii

    $params = array(
                  'message'       =>  "Hurray! This works :)",
                  'name'          =>  "This is my title",
                  'caption'       =>  "My Caption",
                  'description'   =>  "Some Description...",
                  'link'          =>  "http://stackoverflow.com",
                  'picture'       =>  "http://i.imgur.com/VUBz8.png",
              );
    $post = Yii::app() -> facebook -> api("/" . $fbID . "/feed", "POST", $params); 


http://stackoverflow.com/questions/12196576/facebook-php-sdk-publish-stream-oauthexception-200

Unity ~ JSONParse Exception: json error -- not an array

如果你想在Unity 解析 JSON

剛好是用JSONParse也遇到這問題

千萬不要浪費時間去鑽研到底是JSON有問題還是哪裡沒設定好或是code問題

或是再繼續google找其他的library使用

我就是在這鳥問題中try了好久

暈倒0rz


如果你也跟我一樣遇到這鳥問題

想必也是在這網址下載的

https://github.com/tonioloewald/jsonparse

但這版本有問題, 要去抓上一版本才對

到這裡抓2013.2.21的版本
https://github.com/tonioloewald/jsonparse/commits/master

這樣就可以正常working