Browsing articles in "程式相關"
grocerycrud是一個可以快速建立CRUD頁面和功能的一個好工具,但是他的join寫的實在有點死板板,不過好在我們還是可以有一些方法可以解決掉這個問題
首先建立一個model $codeigniterRoot/application/models/$modelName_model.php,下面是程式的內容
<?php
class Crud_classes_students_join extends grocery_CRUD_Model
{
function get_list()
{
if($this->table_name === null)
return false;
$select = "{$this->table_name}.*";
// 在這裡加入我們要額外select的欄位
// $select .= ", user_log.created_date, user_log.update_date";
if(!empty($this->relation))
foreach($this->relation as $relation)
{
list($field_name , $related_table , $related_field_title) = $relation;
$unique_join_name = $this->_unique_join_name($field_name);
$unique_field_name = $this->_unique_field_name($field_name);
if(strstr($related_field_title,'{'))
$select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
else
$select .= ", $unique_join_name.$related_field_title as $unique_field_name";
if($this->field_exists($related_field_title))
$select .= ", {$this->table_name}.$related_field_title as '{$this->table_name}.$related_field_title'";
}
$this->db->select($select, false);
// 這裡寫上我們需要的join語法
$teacherID = $this->session->userdata('userID');
$this->db->join('teacher_student',"users.user_id=teacher_student.student_id and teacher_student.teacher_id=$teacherID");
$obj = $this->db->get($this->table_name);
$results = $obj->result();
return $results;
}
}
接下來在$codeigniterRoot/application/controllers/$controllerName
$crud = new grocery_CRUD();
$crud->set_model($modelName); // 這裡就是把我們剛剛建立的model載入進來
$crud->set_theme('datatables');
$crud->set_table('users');
$crud->set_subject('student');
這樣就可以讓GroceryCRUD根據我們特殊需求去做join,不會再受限於原本的架構了
今天在AWS EC2 micro上面執行composer update的時候跳出了下面的錯誤訊息
PHP Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/S
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 990, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(990): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(832): Symfony\Component\Console\Application->getSttyColumns()
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(797): Symfony\Component\Console\Application->getTerminalDimensions()
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(731): Symfony\Component\Console\Application->getTerminalWidth()
#5 phar:///usr/local/bin/com in phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php on line 990
Fatal error: Uncaught exception 'ErrorException' with message 'proc_open(): fork failed - Cannot allocate memory' in phar:///usr/local/bin/composer/vendor/symfony/console/Symfon
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'proc_open(): fo...', 'phar:///usr/loc...', 990, Array)
#1 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php(990): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Conso
#3 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Conso
#4 phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Conso
#5 phar:///usr/local/bin/com in phar:///usr/local/bin/composer/vendor/symfony/co
google了一下,很多人都說AWS EC2 micro instance遇到這個問題是無解必須把等級往上升一等才能解決,我不信邪,一樣在micro的機器上面做以下的修改
vi /etc/php.ini
把原本的 memory_limit=128M 改成 memory_limit=256M
然後重新啟動apache,再執行一次composer update就可以正常了,到目前為止composer都運作的很順利沒有遇到任何的問題
之前分享如何在AWS EC2上面安裝PHP-APC加速器,有網友留言說可以試試PHP5.5內建的OPcache試試看。我想要試試看OPcache的威力但目前暫時還不想要升級到PHP5.5。好在remi這個源裡面有提供OPcache可以讓我們安裝,下面就跟大家分享一下如何在AWS EC2上面安裝OPcache。
1. 安裝remi repo
首先我們一樣要在AWS EC2中安裝remi這個源,如果你還沒有安裝過,可以參考如何在AWS EC2上面安裝PHP-APC加速器這篇文章的步驟一。
2. 安裝OPcache加速器
指令只有一行
sudo yum install php-pecl-zendopcache
3. 設定OPcache
安裝完OPcache之後,我們必須針對設定檔進行一些設定,設定的參數我是參考使用Zend Opcache加速PHP這篇文章
sudo vi /etc/php.d/opcache.ini
然後根據我參考的那篇文章,做以下的設定調整
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
4. 關閉PHP-APC
如果之前有安裝PHP-APC加速器,但是不想要移除,可以使用下面的方法來關閉
sudo vi /etc/php.d/apc.ini
把extension = apc.so這行最前面加上 ; (分號)註解掉;或者是把apc.enable_opcode_cache改成0(數字零)這樣就可以關閉APC了
5. 最後記得重新啟動Apache
sudo service httpd restart
6. 確認Zend OPcache是否安裝成功
[[email protected]_jp ~]$ php -v
PHP 5.4.17 (cli) (built: Jul 12 2013 21:18:57)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.2, Copyright (c) 1999-2013, by Zend Technologies
當然也可以寫一個phpinfo的頁面來看,不過記得看完之後要把這個檔案刪掉,避免主機上的資訊洩漏。
1. Install Ruby
http://rubyinstaller.org/downloads/
我習慣把開發的環境建置在 D:\Develop\
2. Update Ruby
開啟命令提示字元
D:
cd Develop\Ruby200-x64
gem update --system
3. Install Sass
* Standard Gem
gem install sass
* Prerelease Gem
gem install sass --pre
4. Install compass
gem install compass
5. Install susy
gem install susy
6. Create Projcet
compass create <project name> -r susy -u susy
7. Execute
compass watch
這邊我強烈建議使用console,如果使用其他的套件或工具常常會詭異的發生下面的錯誤
LoadError on line xxx of xxx.file: no such file to load -- susy
最近把PHP升級到5.4之後,原本很習慣使用eAccelerator就沒有repo可以安裝使用。比較了一下之後,發現APC還蠻多人推薦的,因此就決定用它了。
1. 安裝remi repo
在安裝APC加速器之前,我們必須要先安裝remi 這個repo
如果你跟我一樣所使用的AMI是Amazon Linux AMI x64,請使用下面的指令安裝remi
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6.rpm
如果你所使用的是RHEL x64,請同時安裝EPEL這個repo
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
安裝完畢之後,我們必須要啟用remi這個repo
sudo vim /etc/yum.repos.d/remi.repo
把enabled改成1,我習慣也會把remi的權重調整一下,在enabled之前加上這一行
priority=1
2. 安裝APC加速器
2-1 連同APC管理介面一起安裝的指令
sudo yum install apc-panel
2-2 只單純安裝APC加速器
sudo yum install php-pear php-pecl-apc
這樣就完成安裝了
3. 設定APC加速器管理的存取權限
如果在第二步你選擇只安裝APC加速器,那麼可以跳過這個步驟,直接到步驟四
sudo vi /etc/httpd/conf.d/apc-panel.conf
加入我們允許存取的IP
# # APC Control Panel
Alias /apc-panel /usr/share/apc-panel
<Directory /usr/share/apc-panel>
<IfModule mod_authz_core.c>
# Apache 2.4
Require local
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
Allow from 加入你允許存取的IP
</IfModule>
</Directory>
4. 重新啟動Apache
sudo service httpd restart
這樣就完成了PHP-APC加速器的安裝,如果你有安裝APC管理介面,那麼可以在 http://你的ip或domain/apc-panel 看到APC相關的資訊