顯示具有 program_php 標籤的文章。 顯示所有文章
顯示具有 program_php 標籤的文章。 顯示所有文章

星期一, 4月 25, 2011

PC上Codeignitor的網站run不能來,很有可能是AppServ的問題

PC上Codeignitor的網站run不能來,很有可能是AppServ的問題
因為AppServ中讀 .htaccess的功能沒有打開
要改一下httpd.conf的設定
  1. AllowOverride All (None→All)
  2. LoadModule rewrite_module modules/mod_rewrite.so (#去掉)
這樣就行了

星期二, 4月 12, 2011

如何徹底杜絕資料隱碼攻擊

撰寫安全的程式碼 第6回 資料庫安全議題,源自對資料隱碼攻擊的討論,而做好基本認識後,接下來是針對它的特性去防禦

資料隱碼攻擊(SQL Injection)之所以能夠發動,主要是因為資料庫存取程式利用來自於使用者所輸入的內容,做為建構SQL述句的一部份內容,使得最後所建構出來的SQL述句,違背了原設計者的預期,反而提供了別有用心的用途.....more

星期二, 2月 01, 2011

Codeigniter controller 之多重繼承

if (!defined('BASEPATH')) exit('No direct script access allowed');/**
 * Blog Controller
 */
class Blog_Controller extends Controller
{
    
function Blog_Controller() {
        parent
::Controller();
    
}
}
/**
 * Admin Controller
 */
class Admin_Controller extends Controller
{
    
function Admin_Controller() {
        parent
::Controller();
    
}
}
/* End of file MY_Controller.php */
/* Location: ./application/libraries/MY_Controller.php */ 

 

Article:Best way to have multiple parent controllers

星期六, 1月 29, 2011

CodeIgniter 2.0.0 現身

整個就是太開心
這真是最好的新年禮物
CodeIgniter 2.0 今天發佈了 !
結構變得更精簡、更嚴謹
期待官方手冊更新到最新版
等不及要申級了 !

延伸閱讀:CodeIgniter 2.0.0 Released

星期三, 12月 08, 2010

CodeIgniter 推出 1.7.3

CodeIgniter推出了1.7.3版
這次的小更新是針對了安全性的加強
防止在某些特殊的情況下,網站的目錄被看光光
已經在用1.7.2的朋友,只需要更新6個東西就好
  1. 根目錄的index.php
  2. system/codeigniter資料夾
  3. system/database資料夾
  4. system/helpers資料夾
  5. system/language資料夾
  6. system/libraries資料夾
就樣就是最新版的 1.7.3了
當然
最期待的還是CodeIgniter 2.0趕快推出囉

延伸閱讀:CodeIgniter 1.7.3 Released

星期二, 11月 02, 2010

CodeIgniter 2.0

期待很久的CodeIgniter 2.0一直遲遲未公開
期實早在今年年初就有風聲CodeIgniter 2.0出現
連版本的內容與更新的項目都有指出來
但一直到現在都過了11個月了,卻還沒有推出
官網在10/26發出了一篇說明( 這裡 )
說他們正在包裝CodeIgniter 2.0了,相信近期就會公佈
希望這回是說真的呀 !

延伸閱讀:CodeIgniter 2.0: Everything you need to know
延伸閱讀:CodeIgniter 2.0 的發展以及特性改變

星期五, 6月 25, 2010

Subversion 1.6.0

在學程式的人應該都會認識Subversion這位好朋友,它可以幫我們同步、備份、分析我們的程式碼,在一堆程式設計師協同開發一個專案時,可避免code的衝突與確保大家code的同步。

現在Subversion 推出最新版1.6.0,在與Eclipse IDE搭配下,運作得很順、很穩,安裝的方式如下:
  1. 打開Eclipse(for Mac),選擇 Help > Install New Software...
  2. 在Work with的後面,按下Add
  3. 輸入
    Name:Subclipse 1.6.x (Eclipse 3.2+)
    Location:http://subclipse.tigris.org/update_1.6.x
可以全打勾後,按下Finish,就可以安裝了


官方網站:subclipse.tigris.org
延伸閱讀:subclipse Download and Install

星期四, 5月 20, 2010

PHP的時間計算

在2010-05-20再加上30天

$years = date("Y"); //用date()函式取得目前年份格式0000
$months = date("m"); //用date()函式取得目前月份格式00
$days = date("d"); //用date()函式取得目前日期格式00
$day = date("Y-m-d",mktime(0,0,0,$months,$days+30,$years));
echo $day;

星期二, 12月 15, 2009

星期三, 11月 18, 2009

MySQL資料庫教學

愈寫程式愈覺得資料庫(Database)的重要
從最基本的select, insert, update, delete,到簡單搜尋、交叉查尋、甚至全文檢索
才發現自己的資料庫知識不夠豐富
這裡是『MySQL資料庫教學
下列是改善程式效能,重要又實用的部份
  • 7. 改善(最佳化)
  • 12.7. 全文搜尋
  • 13.2.8. Subquery
備註:

星期五, 11月 06, 2009

Eclipse = Aptana + Flash Builder 4 (Flex4)

Eclipse之前是用Flex Builder 3來寫flex,用Aptana來寫PHP
但這二個IDE的核心其實都是Eclipse
所以等於是裝了二套的Eclipse在系統裡跑
這樣不但同時使用起來效能很不好,而且在寫程式時還要一直切來切去
實在不是個好的使用經驗
最好的解決方法,當然就是裝Eclipse,再外掛Aptana和Flash Builder
  • Eclipse可以到 這裡 下載,Mac和Windows版都免安裝就可使用
  • Aptana for Eclipse的plugin點 這裡
  • Flash Builder 4 for Eclipse的plugin點 這裡
都下載好了後,先把Eclipse放到想放的地方去(application下)
再分別安裝Aptana和Flash Builder(記得選plug在剛剛的Eclipse之下)
接下來就可以享受同時寫PHP和Flex的方便了!

備註:
Eclipse PDT本身就支援PHP了,何必還要裝Aptana呢 ?
這是因為Eclipse PDT本身的PHP Engine並不認識code ignitor,所以不會有autocomplete或是code hint,因此安裝Aptana來幫助Eclipse有autocomplete的功能。

星期二, 10月 13, 2009

Remove "index.php" from Codeigniter URL

去掉Codeigniter中,網址的 index.php
有三個步驟:
  1. 打開 config.php (在 system/application/config裡),找到 $config['index_page'] = "index.php" 換成 $config['index_page'] = ""
  2. 建立一個名叫 ".htaccess" 的檔案,並放在網站專案的目錄中。
    這檔案的內容如下(只有五行):
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
  3. 有時候,Codeigniter的 uri_protocol 的判斷會怪怪的,所以我們還是就改一下比較好。一樣打開 config.php (在 system/application/config裡),找到
    $config['uri_protocol'] = "AUTO" 換成 $config['uri_protocol'] = "REQUEST_URI"
完成,就這樣囉!

星期日, 9月 20, 2009

開啟MAMP中的PHP錯誤報告(Error Report)功能

MAMP是在Mac中很方便的一個架站套件,但是它的PHP錯誤報告(Error Report)功能預設是關閉的,這應該是為了給Server用的設定,但是這對我們Designer在寫PHP時很不方便debug,所以當然要打開囉。
  1. 找到在Applications中的MAMP資料夾
  2. 打開conf/php5/php.ini(因為我是用php5)
  3. 找到第270行,應該是這樣:error_reporting = E_ALL
  4. 把第277的display_errors = Off 改成 display_errors = On
  5. 重開Server,完成!

星期五, 6月 26, 2009

CodeIgniter User Guide Version 1.7.1

General

  • Class names must have the first letter capitalized with the rest of the name lowercase.
    ex : class Model_name extends Model {}
  • The file name will be a lower case version of your class name.
    ex : application/models/user_model.php

Controller

  • A Controller is simply a class file that is named in a way that can be associated with a URI
  • If your controller contains a function named _remap(), it will always get called regardless of what your URI contains.
  • To make a function private, simply add an underscore as the name prefix and it will not be served via a URL request. ex: function _utility()

Views

  • Views are never called directly, they must be loaded by a controller.
  • $this->load->view('folder_name/file_name');
  • There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser.
    ex : $string = $this->load->view('myfile', '', true);

Models

  • Models are PHP classes that are designed to work with information in your database.
  • Your models will typically be loaded and called from within your controller functions.
  • Once loaded, you will access your model functions using an object with the same name as your class:
    $this->load->model('Model_name');
    $this->Model_name->function();
  • If you would like your model assigned to a different object name you can specify it via the second parameter of the loading function:
    $this->load->model('Model_name', 'fubar');
    $this->fubar->function();
  • When a model is loaded it does NOT connect automatically to your database.
  • You can tell the model loading function to auto-connect by passing TRUE (boolean) via the third parameter, and connectivity settings, as defined in your database config file will be used:
    $this->load->model('Model_name', '', TRUE);

Helper Functions

  • Helpers are not written in an Object Oriented format. They are simple, procedural functions. Each helper function performs one specific task, with no dependence on other functions.
  • CodeIgniter does not load Helper Files by default, so the first step in using a Helper is to load it. Once loaded, it becomes globally available in your controller and views.
  • Loading Multiple Helpers. ex: $this->load->helper( array('helper1', 'helper2', 'helper3') );
  • all native CodeIgniter libraries are prefixed with CI_ so DO NOT use that as your prefix.

Plugins

  • Plugins work almost identically to Helpers. The main difference is that a plugin usually provides a single function, whereas a Helper is usually a collection of functions.
  • Loading Multiple Plugins. ex: $this->load->plugin( array('plugin1', 'plugin2', 'plugin3') );

Common Functions

  • is_really_writable('path/to/file')
  • config_item('item_key')
  • show_error('message'), show_404('page'), log_message('level', 'message')

Scaffolding

  • Scaffolding is intended for development use only.
  • $this->load->scaffolding('table_name');
  • example.com/index.php/class/secret_word/

URI Routing

  • example.com/class/function/id/
  • example.com/product/1/ => $route['product/(:num)'] = "catalog/product_lookup_by_id/$1"
  • $route['product/:any'] = "catalog/product_lookup";

Error Handling

  • Disabling error reporting will NOT prevent log files from being written if there are errors.

codeIgniter

最近在使用新的手法來開發傳統的php網頁,所用的frame work叫codeIgniter,採用物件導向的寫法,這和Flex的本值很相像(物件導向不都是這樣),所以用起來還覺得滿親切的。
目前還是看它的manuel,會把它的重點慢慢的記下來