2016. 2. 22. 19:14

[PhalconPHP] 팔콘PHP 프래임웍 관련 메모

1. 컨트롤러와는 별개의 뷰와 레이아웃을 적용할 경우(컨트롤러에서)


$this->view->pick('뷰명');

$this->view->setLayout('레이아웃명');


반드시 pick 를 먼저 실행하고 그 다음 setLayout을 사용할 것.

setLayout 을 먼저하고 pick을 할 경우 setLayout은 무시됨.


2. 실행 시 모듈이 로드되지 않는 경우

Starting php-fpm-5.6: Failed loading /usr/lib64/php/5.6/modules/phalcon.so:  /usr/lib64/php/5.6/modules/phalcon.so: undefined symbol: php_pdo_get_dbh_ce


이 경우는 PDO 보다 Phalcon 이 먼저 로드 되서 발생되는 문제로 주로 php.ini 에서 .so 파일을 로드 하지 않고 

별도로 php.d/10-opcache.ini 처럼 각각 따로 설정파일이 있는 경우에 발생한다.

php.ini 에 extension=phalcon.so 를 넣으면 가장 먼저 로드 되기 때문에 발생되는 오류이다.

php.d/에 50-phalcon.ini 파일을 만들고 그안에 extension=phalcon.so 를 넣고 실행하면 된다.


3. Phalcon Dev Tools로 작업 시 프로젝트 디렉토리가 아니라며 오류가 나는 경우

버전업이 되면서 프로젝트 디렉토리를 .phalcon 디렉토리가 존재하는지 확인하는 부분이 추가된듯 함

프로젝트 디렉토리에 .phalcon 디렉토리를 만들어주고 phalcon model 등의 명령을 사용할 것.


4. 모델 find 옵션

ParameterDescriptionExample
conditionsSearch conditions for the find operation. Is used to extract only those records that fulfill a specified criterion. By default Phalcon\Mvc\Modelassumes the first parameter are the conditions."conditions" => "name LIKE'steve%'"
columnsReturn specific columns instead of the full columns in the model. When using this option an incomplete object is returned"columns" => "id, name"
bindBind is used together with options, by replacing placeholders and escaping values thus increasing security"bind" => array("status" =>"A", "type" => "some-time")
bindTypesWhen binding parameters, you can use this parameter to define additional casting to the bound parameters increasing even more the security"bindTypes" =>array(Column::BIND_PARAM_STR,Column::BIND_PARAM_INT)
orderIs used to sort the resultset. Use one or more fields separated by commas."order" => "name DESC,status"
limitLimit the results of the query to results to certain range"limit" => 10
offsetOffset the results of the query by a certain amount"offset" => 5
groupAllows to collect data across multiple records and group the results by one or more columns"group" => "name, status"
for_updateWith this option, Phalcon\Mvc\Model reads the latest available data, setting exclusive locks on each row it reads"for_update" => true
shared_lockWith this option, Phalcon\Mvc\Model reads the latest available data, setting shared locks on each row it reads"shared_lock" => true
cacheCache the resultset, reducing the continuous access to the relational system"cache" => array("lifetime"=> 3600, "key" => "my-find-key")
hydrationSets the hydration strategy to represent each returned record in the result"hydration" =>Resultset::HYDRATE_OBJECTS


5. 모델에서 어트리뷰트(필드) 가져오고 null로 초기화

$metaData = new \Phalcon\Mvc\Model\MetaData\Memory();
$attr = (array)$metaData->getAttributes(new BaseModel\Abc());
$data = array_combine($attr, array_fill(0, count($attr), null));