Showing posts with label Web Programming. Show all posts
Showing posts with label Web Programming. Show all posts

Thursday, April 16, 2009

欲在Symphony(PDO使用Propel)下從DB拿多列的資料,目前看到這是唯一可行的方法:



$connection = Propel::getConnection();
$query = 'SELECT MAX(%s) AS max FROM %s'; //写你要查询的sql
$query = sprintf($query, ArticlePeer::CREATED_AT, ArticlePeer::TABLE_NAME);
$statement = $connection->prepare($query);
$statement->execute();
$resultset = $statement->fetchAll(PDO::FETCH_OBJ);

最後一行如果用fetch就是只拿一列,fetchAll就拿所有列。 $resultset是個array,裡面有所有列的資料。

但這是Propel裡的東西,而非Symfony本身的。 Symfony本身的doSelect()只能拿到第一筆的資料,但列的數目又是對的。 我查了好久的文件還是找不到為什麼會這樣。 doSelectstmt()也懶得試了… Symfony真的很鳥啊!

Edit:
用了doSelect

$c = new Criteria();
$c->add(ListsPeer::MAC_ADDRESS, $mac, Criteria::EQUAL);
$stmt = ListsPeer::doSelectStmt($c);
$ids = array();
while($res = $stmt->fetchColumn(1)) {
echo $res;
}

還是可以用的啦… 算了。

Tuesday, April 14, 2009

Using Propel ORM. My step-by-step walkthrough to create a working model:

There are several commands concerning the ORM which ultimately works toward building a Model.

The schema.yml, which represents the schema for a Model, can be either typed by hand, or imported and built directly from a database. To do so, type:


symfony propel:build-schema


Or if there is no corresponding database in the db, you may enter the schema by hand. After doing so, type


symfony propel:build-sql


to convert the schema into SQL commands. The actual SQL commands are stored in the lib.model.schema.sql inside the data/sql/ directory of the project folder. You can actually skip the build-sql step by editting this file directly...

After the build-sql command, you can insert the SQL commands into the db, provided that you have already configured the connection to your db. Use either


symfony configure:database "mysql:host=localhost;dbname=db_name"


or edit your /config/databases.yml and /config/propel.ini

Once the connection to the db server are set, insert the SQL by typing:


symfony propel:insert-sql


This step will remove tables with the same names defined in the SQL in the db. Clearing Symfony cache is recommended after this step:


symfony cc



Then it's finally time to build Model so that we can use the ORM to access db:


symfony propel:build-model


Note: Actually, you MAY build Model directly from schema.yml, but it'd be pretty pointless without making sure your Model has a working db connection, right?

Wednesday, April 01, 2009

為了某個不足為外人道之原因,在下做了這件感覺起來很蹩腳很挫的事… >_< 真的要拿出去討論的話,可能我還得好一陣子的心理建設才敢拿出去曝光… 但如果有幸有哪位前輩高手不幸在blogger看到這篇的話,還不吝留下您的意見; 像是更好的做法… 等等。 小弟感激不盡。m(_ _)m

以下這一段是要達到效果的描述:
一個母網頁頁面,必須將其cookie丟到其所包含之一個iframe裡所指到的一個不同domain的網頁(姑且稱此網頁為子網頁)。 而子網頁必須要能拿到母網頁的cookie來做一些… 見不得人的事兒。 在開啟母網頁同時,即需可看到母網頁下iframe裡的子網頁根據母網頁的cookie所做出的頁面。


為了做這件事,在擦股溝擦了好一會兒後,所做出的解答如下:

母頁面就只是一個html,除了一些讀寫刪cookie的Javascript functions外,還包括兩個iframe:


<iframe id="test1" src ="http://howard.com/cookiecutter.php?cooke_name=cookie_value" width="300px" height="100px" >


cookiecutter.php:



<?php
header("P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR");
$keys = array_keys($_GET);
header("Set-Cookie: ".$keys[0] ."=" . $_GET[$keys[0]]. "; domain=.howard.com; path=/"); ?>

cookiecutter.php較特別的是那一行header P3P的code。 P3P全名為:「The Platform for Privacy Preferences」。 基本上就是跟網頁瀏覽器說,我知道我現在要做的事不合規定或不安全,但你就讓我做就是了。 然後下一行header set-Cookie就在howard.com上設一個名字和值為cooke_name和cookie_value的cookie。


值得注意的是,如果拿掉P3P那一行,剛剛設的這個cookie在母頁上將拿不到。


如此,雖然是達成了目標,但是不管怎麼看,都應該只能算是很粗糙的解決方案,並不是真正的cookie passing。 小弟在此拋磚引玉,還希望各位先進們指教一下。

Monday, March 30, 2009

A fragment identifier is defined by RFC 3986 as an optional component of a URI reference, and it must conform to a certain syntax. The syntax requires that the fragment identifier be separated from the rest of the URI reference by a # (number sign) character. The separator is not considered part of the fragment identifier.

Basically it looks like http://www.foo.org/foo.html#fragment-identifier.

To use it in Javascript, it is simply "window.location.hash"

This is an imitation of PHP $_GET, in pure Javascript.

From http://www.11tmr.com/11tmr.nsf/D6Plinks/MWHE-695L9Z




function getURLParam(strParamName){
     var strReturn = "";
     var strHref = window.location.href;
     if ( strHref.indexOf("?") > -1 )
    {
         var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
                if (
                aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
     return unescape(strReturn);
}

Thursday, March 19, 2009

今天又學到了一個幫助CSS在IE7、IE6和Firefox上都能跑得一樣,但屬旁門左道的小技巧。 只能心裡腹誹IE不遵守規範…

以下例的css作為例子:
.context_bar_form_field
{
height: 15px;
#height: 15px;
_height: 21px;
}

The first setting will apply to all browsers,
The second setting will only apply to Microsoft Internet Explorer browsers
The third setting will only apply to IE browsers 6.0 and older
如何,是否也想像我一樣,忍不住來一句:「他奶奶的IE」呢?

Tuesday, March 17, 2009

CSS stacking effect

今天在跟BT Box的網頁頁面的css奮鬥了一整天,一直無法將下拉式選單蓋過其下面的頁面元素。 就在要放棄之餘,突然發現了這篇文章:

http://css-discuss.incutio.com/?page=OverlappingAndZIndex

才知道原來 z-index 是不能亂設的。 譬如說想要一個dd元素可以蓋過別的頁面元素,這個dd元素的母元素盡量不要設z-index, 而只為此dd元素設一個高過想要蓋過的頁面元素的 z-index 的 z-index。 但似乎這個文章所說尚不止如此,得要好好再讀一下。


以前那他媽的知道這種隱藏版規則啊! (翻桌) 唉…