#BEFORE

1
2
3
4
5
6
7
8
9
10
11
12
13
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
window.MozBlobBuilder || window.MSBlobBuilder;
window.URL = window.URL || window.webkitURL;

var bb = new BlobBuilder();
bb.append('body { color: red; }');
var blob = bb.getBlob('text/css');

var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = window.URL.createObjectURL(blob);

document.body.appendChild(link);

#NOW

1
2
3
4
5
6
7
8
window.URL = window.URL || window.webkitURL;

var blob = new Blob(['body { color: red; }'], {type: 'text/css'});

var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = window.URL.createObjectURL(blob);
document.body.appendChild(link);

#SO

Just New Blob()…no more BlobBuilder()

two ways to use it

#1 use blade on controller

in controller, you need to assign a template for controller.

1
protected $layout = 'layouts.master';

and then in each function action. assign whatever need to assign for show content on template. like in blade template. I have a content section. Therefore, i need to set a value or view to 「Content」

1
$this->layout->content = something or View::make('something');

in blade template. there are 2 ways to define var.

  1. @yield(『something』)

if use first method; then in view, it needs to create a section something. ex

1
2
3
@section('content')
xxxx
@endsction

for method 2. no need to create a section to contain page content.

From the VFP9 helpfile:

Specifies the amount of memory (address space) in pages that Visual FoxPro allocates at startup or a Visual FoxPro MTDLL COM Server allocates per thread for the internal program cache (memory used to run programs). Each page of memory is equal to 64K so the default setting equates to an allocation a little over 9MB. As the cache is filled, Visual FoxPro will try to flush it to remove unused items. It is possible that Visual FoxPro cannot free enough memory in which case an Error 1202 is generated (Program is too large). Adjusting the PROGCACHE setting can prevent this error from occurring.

Note: While this setting can be used for the Visual FoxPro development product or normal runtime applications, it is primarily intended for MTDLL COM Servers where many threads are often created for a single server. In Visual FoxPro 9.0, the default value for MTDLL COM Servers is -2.

When the value of nMemoryPages is greater than 0, Visual FoxPro allocates a fixed program cache. You can specify between 1 and 65000.

If you specify 0 for nMemoryPages, no program cache is used. Instead, Visual FoxPro uses dynamic memory allocation based on determinations made by the operating system.

If you pass a value for nMemoryPages that is less than 0, Visual FoxPro uses dynamic memory allocation but is limited to the specified memory (nMemoryPages * 64K). When the limit is reach, Visual FoxPro will flush allocated programs to free memory.

You can call SYS(3065) to determine the current PROGCACHE setting. CLEAR PROGRAM will attempt to clear unreferenced code regardless of this setting.

Note: The Visual FoxPro OLE DB Provider ignores this setting since it uses dynamic memory allocation (PROGCACHE=0).

Default: 144 (-2 for MTDLL)

「The setting is the number of pages of memory you want allocated. Each page is equivalent to 64K of memory. You can set the PROGCACHE from 1 to 65,000 (positive or negative) to designate how much memory is allocated. If you specify zero, no program cache is used and VFP uses dynamic memory allocation determined by the operating system. If you set the PROGCACHE to a negative number, VFP uses dynamic memory allocation, but is limited to the number of memory pages you specified. The default setting is 144 (over 9 megabytes) for single-threaded EXEs and the VFP IDE, and -2 (128 kilobytes) for a multi-threaded DLL. The VFP OLE DB Provider does not use this setting because it uses dynamic memory allocation.」

Ref: http://fox.wikis.com/wc.dll?Wiki~ProgCache

Controller

Controllers是用來處理商業邏輯及資料與view之間的介面(負責將資料input//output 給model,與資料庫的溝通就交給model去處理了)

controller需要配合route的設定才可被view呼叫使用。

例如: route::get(『something』,『[email protected]』)

當使用者跑到 http://website/something時, 就會呼叫route內所對應的controller及action.

發現,這種指定的方式,當頁面很多的時候就會變得很麻煩。 所以laravel的route提供另外一種指定的方式

route::controller(『something』,『someController』)

此種設定的方式,適用於restFUL的controller, (get,post,put,delete)四種交換模式的相關動作。

一般而言,只是讀取一個頁面的時候,都是透過 get的method取得回應的。所以在controller內action的命名, 就是用getSomection()為命名的方式,網址就是http://website/something/someaction (小寫, Controller內的action name 是大寫). 如果action的名稱是SomeAction時,注意 是兩個大寫字母 網址就會變成 http://website/something/some-action (破折號作為連結的符號)

同理: 如果遇到form post時, 就是呼叫postSomeaction()

以上為controller的基本呼叫方式。

#database config path

/app/config/database.php

#star up path

serverName/laravel/public


#php artisan migrate 這裡migrate的觀念與EntityFramework 5 Code First的觀念相同。

migrate:install

安裝Migration table, 會在資料庫中創建一個migrateion table, 紀錄migration版本

migrate:make somethingsomething

建立新版的資料庫異動檔案

migrate

執行資料庫格式升級 --> function up()

migrate:rollback

執行資料庫格式降級 --> function down()

migrate table file location : app/database/migrations/

升級動作
1
2
3
4
5
6
7
8
9
10
11
12
function up(){
// create new table
Schema::table('users', function($table)
{
$table->create();
$table->increments('id');//id fields with AUTO_INCREMENT
$table->string('email');//email field with varchar(255)
$table->string('real_name',100);//real_field with varchar(100)
$table->string('password');
$table->timestamps();// created_at,updated_at timestamps(2 fields)
});
}

降級動作
1
2
3
4
function down(){
//Drop Table
Schema::drop('users');
}

啟動方式

1
2
3
4
5
6
7
8
9
10
$di->set('router', function () {
$router = new \Phalcon\Mvc\Router();
$router->add("/:controller/:action/:params", array(
'controller' => 1,
'action' => 2,
'params' => 3
));

return $router;
});

Defining Route

Placeholder Regular Expression Usage
/:module /([a-zA-Z0-9_-]+) Matches a valid module name with alpha-numeric characters only
/:controller /([a-zA-Z0-9_-]+) Matches a valid controller name with alpha-numeric characters only
/:action /([a-zA-Z0-9_]+) Matches a valid action name with alpha-numeric characters only
/:params (/.) Matches a list of optional words separated by slashes. Use only this placeholder at the end of a route
/:namespace /([a-zA-Z0-9_-]+) Matches a single level namespace name
/:int /([0-9]+) Matches an integer parameter

/:params : 只能放在router的最後面

#controller內取得route裡面參數的方式

1
2
3
$this->dispatcher->getParam(0);
$this->dispatcher->getParam('paraName');
$this->dispatcher->getParams(); <=array

#如果是/?var=value

就用原本$_GET[『』]的方式取值就可以了

  1. commit your code
1
2
git add .
git commit -m "xxxx"
  1. merge your branch to master 以master為主要branch
1
2
3
4
5
git checkout master
git merge [module name]<= this should be branch name
```

3. update

git pull origin master

1
2
3
檢查是否有conflict要修

4. push至origin

git push origin master:[module name]

1
2
3
4

5. 通知alvin合併

6. 拉別人的code

git add remote kyo /home/kyo/web/mc2

1
2

7. 直接合併於目前的branch EX. 拉KYO的master

git pull remote kyo master

1
2

8. 拉成新的branch EX. 拉KYO的master為自己的kyo branch

git fetch remote kyo master:kyo

1
2
3
4

9. git 環境設定

###設定個人資訊

git config --global user.name 「Your Name」

git config --global user.email [email protected]


###設定git環境

cd ~ #進入個人home目錄 
ex./home/fish
vi .gitconfig 

####編輯git環境檔,貼上以下環境設定變數

[color]
 
 branch = auto
 
 diff = auto
 
 status = auto

[color "branch"]

  current = yellow reverse
 
  local = yellow 

  remote = green

[color "diff"]
 
 meta = yellow bold
 
 frag = magenta bold
 
 old = red bold
 
 new = green bold

[color "status"]

  added = green
 
  changed = red

In Phalcon Model system. 是根據ORM的架構,讓資料表物件化,讓在資料讀取或是寫入的動作上,可以利用物件的特性去操作。

初始設定

1
2
3
4
5
6
7
8
9
10
11
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di->set('db', function() use ($config) {
return new DbAdapter(array(
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname
));
});

上列的動作會開啟與資料庫中間的連線關係,$config會去讀取所指定的設定文件

Model文件預設的命名方式為table名稱,例如:

1
2
3
class Rebots extends \Phalcon\Mvc\Model
{
}

官方文件建議,要在Model文件中描述資料表的欄位,以減少使用伺服器的記憶體資源。

如果Model的名稱與資料庫資料表名稱不同時,可以透過以下的方式重新設定所關聯的資料表名稱

1
2
3
4
5
6
7
8
9
10
public function initialize()
{
$this->setSource('Rebots');
}
```

#於Controller中使用Model讀取資料

讀取清單的方式有幾種

ModelName::find(condition)

1
2
3

當找到筆資料時,所回傳的物件可以直接修改後,並儲存(Update)

$result = ModelName::find(『id=1』); $result->fieldName = 「something something」; $result->save(); <=將資料回傳至資料庫中

1
2
3

新增動作

$result = new ModelName(); $result->fieldName = 「something something」; $result->save();

1
2
3

刪除動作

$result = ModelName::find(condition); if ($result != false) { // 執行刪除 if ($result->delete() == false) {
echo 「Delete Failed」; foreach ($result->getMessages() as $message) { echo $message, 「\n」; } } else { echo 「Deleted successfully!」; } }

#Hierarchical Rendering Phalcon當在使用View的時候,執行的順序是

  1. app/views/index.volt
  2. app/views/layouts/指定.volt(有[指定時][1],才會發生)
  3. app/views/layouts/{{controllerName}}.volt
  4. app/views/{{controllerName}}/xxx.volt

依造這種順序,

在index.volt裡面的{{content()}},就會去呼叫app/views/layouts裡面的內容, 然後再app/views/layouts裡面的{{content()}}就是呼叫app/views/{{controllerName}}/xxx.volt的內容

在Controller裡面所設定的變數,則上述三種xxx.volt都可以用

[1]: 如果要指定template時, 可以用下列的方式設定, 這樣子就會去讀取app/views/layouts/common.volt的內容了,

1
2
3
4
public function initialize()
{
$this->view->setTemplateAfter('common');
}
這一個指定template的動作,執行順序會插在app/views/index.volt跟app/views/layouts/{{controllerName}}.volt中間

#Using Partials

如果想要在view中間插入partials的方式很簡單

如果是使用volt語法的:

1
2
3
{{ partial(view path) }}
//with parameters
{{ partial(view path, ['links': $links]) }}

一般的語法

1
2
3
<?php $this->partial(view path) ?>
//with parameters
<?php $this->partial(view path, array('id' => $site->id, 'size' => 'big')) ?>