Hiển thị các bài đăng có nhãn php. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn php. Hiển thị tất cả bài đăng
Thứ Bảy, 27 tháng 4, 2013
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;
}
}
Thứ Năm, 25 tháng 4, 2013
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
Thứ Năm, 14 tháng 3, 2013
Yii ~ get db insert id
if($model->save())
{
$model->id;
}
reference
http://www.yiiframework.com/forum/index.php/topic/12776-get-last-inserted-id/
Thứ Hai, 4 tháng 3, 2013
Yii ~ send email, phpmailer
Bản tóm tắt này không có sẵn. Vui lòng
nhấp vào đây để xem bài đăng.
Yii ~ use session
Yii::app()->session['var'] = 'value';
echo Yii::app()->session['var']; // Prints "value"
reference
http://www.larryullman.com/2011/05/03/using-sessions-with-the-yii-framework/
echo Yii::app()->session['var']; // Prints "value"
reference
http://www.larryullman.com/2011/05/03/using-sessions-with-the-yii-framework/
Thứ Năm, 17 tháng 1, 2013
PHP ~ 網站設定的一種做法
一般網站應該都會有個config檔
向asp.net就是Web.config
php......沒有規定.....但似乎一般都會被叫做config.php
裡面就放些網站設定~~~DB連線設定的參數
最近弄網站我換了一個做法.....
除了把config分開成config.php跟configDB.php之外
還弄了一個configSetting.php
由於某些原因.......
我有超級高頻率的修改config檔.....可能改ini_set, 或一些參數等等等
每次小改一下要做測試~~~就FTP傳到server在run
可是我本機的設定......當然不會跟server一模一樣
有時候server還分live server跟testing server.........db設定當然也不一樣
每次都弄到亂七八糟#@%$#^$%^$%&^&$@^%$#@^$%^
傳錯發生的次數不少次.......而且搞剛~麻煩~混亂
所以我才弄了一個configSetting.php.........
裡面就一行code設定我要讀取哪種設定
可能定義configSetting為live或 local或 liveTest
config.php檔就是死的
可能switch case 'live': case 'local'的設定各為怎樣怎樣
每次有更動就照樣上傳
configSetting傳一次就好~~~~~之後就別再上傳取代
這樣真的大大減少混亂的情況發生也減少很多修修改改或註解程式碼的工
一種做法~~~~供參考A_A
Thứ Tư, 12 tháng 12, 2012
PHP ~ curl https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
reference
http://taichunmin.pixnet.net/blog/post/35782941-%5Bphp%5Dcurl%E4%BD%BF%E7%94%A8https%E9%81%87%E5%88%B0ssl-certificate-problem
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
reference
http://taichunmin.pixnet.net/blog/post/35782941-%5Bphp%5Dcurl%E4%BD%BF%E7%94%A8https%E9%81%87%E5%88%B0ssl-certificate-problem
Thứ Tư, 28 tháng 11, 2012
PHP ~ curl 使用感想XD
有些網頁
可能不是簡單的對他要求網址就會把他的網頁傳回來給你
雖然大多是這樣~
但有些網頁是要透過post傳資料後才回傳結果給你
如果想透過程式去抓取這些資料
則要模擬你發送這些資訊給對方server, 對方再回傳東西
如果用PHP可能可以用Peal的HTTP_Request2或是curl做到
但還有一種少數情況.....
不是假裝發post資料給對方server他就認你
我就遇到這問題.......
他還會看你是從哪裡來的
再看要不要傳資料給你
今天解決這問題也是我透過firebug監看網頁上操作時發送的資訊
才發現可以再嘗試多傳送這些參數給server看他認不認得出是正常使用者去瀏覽她的網頁
多次嘗試終於........我找到要多傳哪個關鍵參數給server
他才真的以為我是正常管道去讀取這網頁
我也是搞好久才發現到這個.....
就是Request Headers那一排
這邊firebug很清楚明瞭的列出傳了那些header過去
於是我才想到......可以不只傳post還可以傳假的header資訊給他試試看
過程我試了改 Agent, cookie, host, Referer
試到Referer
才成功............
因為不知道怎麼傳這些header參數所以也是一直google找資料= =
最後弄出來真的......好家在0rz
這邊我是用curl做的
才發現php的curl真的很強大,還可以亂真的XD
curl_setopt($ch, CURLOPT_REFERER, 'http://www.xxxxx.com.tw/ggggggxxxx');
這段code就是傳header跟server說我是從哪裡來的
如果沒傳, 他就以為你亂搞
可是有傳~~~~他就覺得你是正常人~~~~才回傳資料給你
可能不是簡單的對他要求網址就會把他的網頁傳回來給你
雖然大多是這樣~
但有些網頁是要透過post傳資料後才回傳結果給你
如果想透過程式去抓取這些資料
則要模擬你發送這些資訊給對方server, 對方再回傳東西
如果用PHP可能可以用Peal的HTTP_Request2或是curl做到
但還有一種少數情況.....
不是假裝發post資料給對方server他就認你
我就遇到這問題.......
他還會看你是從哪裡來的
再看要不要傳資料給你
今天解決這問題也是我透過firebug監看網頁上操作時發送的資訊
才發現可以再嘗試多傳送這些參數給server看他認不認得出是正常使用者去瀏覽她的網頁
多次嘗試終於........我找到要多傳哪個關鍵參數給server
他才真的以為我是正常管道去讀取這網頁
我也是搞好久才發現到這個.....
就是Request Headers那一排
這邊firebug很清楚明瞭的列出傳了那些header過去
於是我才想到......可以不只傳post還可以傳假的header資訊給他試試看
過程我試了改 Agent, cookie, host, Referer
試到Referer
才成功............
因為不知道怎麼傳這些header參數所以也是一直google找資料= =
最後弄出來真的......好家在0rz
這邊我是用curl做的
才發現php的curl真的很強大,還可以亂真的XD
curl_setopt($ch, CURLOPT_REFERER, 'http://www.xxxxx.com.tw/ggggggxxxx');
這段code就是傳header跟server說我是從哪裡來的
如果沒傳, 他就以為你亂搞
可是有傳~~~~他就覺得你是正常人~~~~才回傳資料給你
PHP ~ get number only
$output = preg_replace ( '/[^0-9]/', '', $string );
reference
http://stackoverflow.com/questions/5474088/php-regular-expression-filter-number-only
reference
http://stackoverflow.com/questions/5474088/php-regular-expression-filter-number-only
Thứ Ba, 20 tháng 11, 2012
PHP ~ use curl do POST
$toURL = "http://SomeDomain/SamplePath?SomeVar=XX";
$post = array(
"a"=>"123",
"b"=>"321",
);
$ch = curl_init();
$options = array(
CURLOPT_URL=>$toURL,
CURLOPT_HEADER=>0,
CURLOPT_VERBOSE=>0,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible;)",
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>http_build_query($post),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
source
http://blog.roodo.com/esabear/archives/16358749.html
$post = array(
"a"=>"123",
"b"=>"321",
);
$ch = curl_init();
$options = array(
CURLOPT_URL=>$toURL,
CURLOPT_HEADER=>0,
CURLOPT_VERBOSE=>0,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible;)",
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>http_build_query($post),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
source
http://blog.roodo.com/esabear/archives/16358749.html
Thứ Ba, 13 tháng 11, 2012
phpQuery ~ remove tag in html
此範例為使用phpQuery進去把該物件的img標籤取代掉
然後再取html出來
$feature = pq('blockquote:eq(0)');
foreach ($feature->find('img') as $img) {
$img = pq($img);
$img -> replaceWith('');
}
$feature = pq($feature) -> html();
然後再取html出來
$feature = pq('blockquote:eq(0)');
foreach ($feature->find('img') as $img) {
$img = pq($img);
$img -> replaceWith('');
}
$feature = pq($feature) -> html();
Thứ Năm, 8 tháng 11, 2012
Thứ Sáu, 19 tháng 10, 2012
PHP ~ phpQuery foreach example
$groups = pq('.type8 tr:gt(0)');
foreach($groups as $group){
$x = pq($group)->find('td:eq(1)')->text();
print $x.', ';
}
reference
http://stackoverflow.com/questions/5994022/phpquery-get-the-values-from-each-td
foreach($groups as $group){
$x = pq($group)->find('td:eq(1)')->text();
print $x.', ';
}
reference
http://stackoverflow.com/questions/5994022/phpquery-get-the-values-from-each-td
Thứ Tư, 17 tháng 10, 2012
PHP ~ class.upload.php upload origin image when image lower than resize x,y
$handle -> image_x = 800;
$handle -> image_y = 800;
$handle -> image_ratio = true;
$handle -> image_resize = true;
$handle -> image_ratio_no_zoom_in = true;
$handle -> image_ratio_no_zoom_out = false;
reference
http://www.verot.net/php_class_upload_docs.htm
$handle -> image_y = 800;
$handle -> image_ratio = true;
$handle -> image_resize = true;
$handle -> image_ratio_no_zoom_in = true;
$handle -> image_ratio_no_zoom_out = false;
reference
http://www.verot.net/php_class_upload_docs.htm
Thứ Hai, 24 tháng 9, 2012
Yii ~ use CKEditor
到這裡下載ckeditor-integration
http://www.yiiframework.com/extension/ckeditor-integration/
解壓縮丟到extensions裡
然後下載ckeditor丟到root
http://ckeditor.com/download
像我就是丟到yii/xxxxx/底下
在View裡面使用ckeditor的sample code
$this -> widget('ext.ckeditor.CKEditorWidget', array("model" => new Event,
"attribute" => 'content',
"defaultValue" => $item['content'],
"config" => array("height" => "400px", "width" => "80%", "toolbar" => "Full")));
http://www.yiiframework.com/extension/ckeditor-integration/
解壓縮丟到extensions裡
然後下載ckeditor丟到root
http://ckeditor.com/download
像我就是丟到yii/xxxxx/底下
在View裡面使用ckeditor的sample code
$this -> widget('ext.ckeditor.CKEditorWidget', array("model" => new Event,
"attribute" => 'content',
"defaultValue" => $item['content'],
"config" => array("height" => "400px", "width" => "80%", "toolbar" => "Full")));
Yii ~ use Upload class
想當初做網站處理圖片的部分
我都是包Upload這個class來做圖片的處理
http://www.verot.net/php_class_upload_docs.htm
現在用yii的framework
想不到也可以用
這邊下載
http://www.yiiframework.com/extension/upload/
安裝方法就是整包丟進extension
然後這邊是我的sample code
Yii::import('application.extensions.upload.Upload');
// receive file from post
if (isset($_FILES['pic'])) {
$Upload = new Upload($_FILES['pic']);
$Upload -> jpeg_quality = 100;
$Upload -> no_script = false;
$Upload -> image_resize = true;
$Upload -> image_x = 700;
$Upload -> image_y = 500;
$Upload -> image_ratio = true;
// some vars
$destPath = Yii::app() -> getBasePath() . '/../img/origin/' . $this -> id . '/';
$destName = $item -> id;
// verify if was uploaded
//origin img
if ($Upload -> uploaded) {
$Upload -> file_new_name_body = $item -> id;
$Upload -> file_new_name_ext = 'png';
$Upload -> file_auto_rename = false;
$Upload -> file_overwrite = true;
$Upload -> process($destPath);
}
//thumb
$destPath = Yii::app() -> getBasePath() . '/../img/thumb/' . $this -> id . '/';
if ($Upload -> uploaded) {
$Upload -> file_new_name_body = $item -> id;
$Upload -> file_new_name_ext = 'png';
$Upload -> file_auto_rename = false;
$Upload -> file_overwrite = true;
$Upload -> image_resize = true;
$Upload -> image_x = 120;
$Upload -> image_y = 180;
$Upload -> image_ratio = true;
$Upload -> process($destPath);
}
}
我都是包Upload這個class來做圖片的處理
http://www.verot.net/php_class_upload_docs.htm
現在用yii的framework
想不到也可以用
這邊下載
http://www.yiiframework.com/extension/upload/
安裝方法就是整包丟進extension
然後這邊是我的sample code
Yii::import('application.extensions.upload.Upload');
// receive file from post
if (isset($_FILES['pic'])) {
$Upload = new Upload($_FILES['pic']);
$Upload -> jpeg_quality = 100;
$Upload -> no_script = false;
$Upload -> image_resize = true;
$Upload -> image_x = 700;
$Upload -> image_y = 500;
$Upload -> image_ratio = true;
// some vars
$destPath = Yii::app() -> getBasePath() . '/../img/origin/' . $this -> id . '/';
$destName = $item -> id;
// verify if was uploaded
//origin img
if ($Upload -> uploaded) {
$Upload -> file_new_name_body = $item -> id;
$Upload -> file_new_name_ext = 'png';
$Upload -> file_auto_rename = false;
$Upload -> file_overwrite = true;
$Upload -> process($destPath);
}
//thumb
$destPath = Yii::app() -> getBasePath() . '/../img/thumb/' . $this -> id . '/';
if ($Upload -> uploaded) {
$Upload -> file_new_name_body = $item -> id;
$Upload -> file_new_name_ext = 'png';
$Upload -> file_auto_rename = false;
$Upload -> file_overwrite = true;
$Upload -> image_resize = true;
$Upload -> image_x = 120;
$Upload -> image_y = 180;
$Upload -> image_ratio = true;
$Upload -> process($destPath);
}
}
Thứ Bảy, 22 tháng 9, 2012
Yii ~ load config
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster@example.com',
'myParam'=>'myValue',
),
$param=Yii::app()->params['myParam'];
reference
http://www.yiiframework.com/forum/index.php/topic/10559-how-to-load-configuration-set-in-configmainphp/
// this is used in contact page
'adminEmail'=>'webmaster@example.com',
'myParam'=>'myValue',
),
$param=Yii::app()->params['myParam'];
reference
http://www.yiiframework.com/forum/index.php/topic/10559-how-to-load-configuration-set-in-configmainphp/
Chủ Nhật, 9 tháng 9, 2012
Discuz ~ config files need modify when moving server
不知道為什麼不把config統一弄一個檔案就好= =
config/config_global.php
config/config_ucenter.php
uc_server/data/config.inc.php
config/config_global.php
config/config_ucenter.php
uc_server/data/config.inc.php
Thứ Năm, 6 tháng 9, 2012
yii ~ set timezone, taiwan
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Test',
'timeZone'=>"Asia/Taipei",
reference
http://www.yiiframework.com/forum/index.php/topic/5976-convert-time-into-different-timezones/
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Test',
'timeZone'=>"Asia/Taipei",
reference
http://www.yiiframework.com/forum/index.php/topic/5976-convert-time-into-different-timezones/
Thứ Tư, 5 tháng 9, 2012
yii ~ Simple Authentication, user login
照著做
沒意外應該OK
我是參考這網址做的~~
http://www.larryullman.com/2010/01/04/simple-authentication-with-the-yii-framework/
沒意外應該OK
我是參考這網址做的~~
http://www.larryullman.com/2010/01/04/simple-authentication-with-the-yii-framework/
Đăng ký:
Bài đăng (Atom)

