2013年9月4日 星期三

joomla心得

***** 20130904_0100 *****
( 西螺人主機晚上有時候ssh會連不進去 )
中文化:
http://www.joomla.org.tw/tutorial/item/%E5%AE%89%E8%A3%9D%E7%B9%81%E9%AB%94%E4%B8%AD%E6%96%87%E8%AA%9E%E8%A8%80%E6%AA%94
1. 進入管理區 - http://www.my.com/administrator/
2. 在上方的選單中選取「Extension」選單,再選取它的子選單「Extension Manager」=> 點按中間那一排連結的「Install Languages」連結 => 勾選「Chinese Traditional」 => 點按右上角的「Install」圖示按鈕
3. 遇到問題 - 出現錯誤訊息 - "Install path does not exist" ( 因為部份資料夾不可寫入 )
4. 解法 -
http://www.joomla.org.tw/component/kunena/Joomla-25x/21733-%E5%AE%89%E8%A3%9Djoomla-v2-5-2%E7%89%88%E5%BE%8C%E7%84%A1%E6%B3%95%E4%B8%AD%E6%96%87%E5%8C%96
下這行指令
$ chmod 777 administrator/manifests/packages/ administrator/language/ language/ tmp/
然後執行步驟2. ,即可完成安裝
5. 設定預設語言 - 後台選"Extensions" => "Language Manager" => 可以設定前台(Site)和後台(Administrator)的預設語言(點星星圖示即可)
ps.
http://docs.joomla.org/Languages_cannot_be_installed_using_install_languages
3.0版本作法(未測試) - 1. 下載預言包,手動安裝 2. 用他patch裡面的fix到joomla中

***** 20130905_0200 *****
開始閱讀joomla 2.5 文件:
http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5
components資料夾(前、後台)是放前後台網頁內容的資料夾,需照文件中命名規則走
在前台新增一頁:
yoursite/components/com_helloworld/helloworld.php # 內容為Hello World!
可以使用這頁開啟 yoursite/index.php?option=com_helloworld
出現錯誤:Error loading component: com_helloworld, 1  *3
http://www.joomlapolis.com/forum/154-advanced-members-support/161857-solved-error-loading-component-comcommunity-1
I disabled a selection of JEvent modules which resolved the issue.
http://joes32blog.blogspot.tw/2009/12/joomla-15-jevents.html
照這篇方法,後台找不到manage events
 --- 以上先暫停,先從JControllerLegacy 、 JModelItemLegacy、 JModelFormLegacy開始 ---

***** 20130907_0230 *****
開發一個MVC/基本元件( Developing a MVC Component/Developing a Basic Component )
http://docs.joomla.org/Developing_a_Model-View-Controller_%28MVC%29_Component_for_Joomla!2.5_-_Part_01
( 簡中教程:http://www.xingzai.org/joomla-doc/joomla-2-5-mvc-%E7%BB%84%E4%BB%B6%E5%BC%80%E5%8F%91%E6%95%99%E7%A8%8B%E3%80%901%E3%80%91.html )
原本是在joomla專案根目錄下直接建立目錄和檔案,在 index.php?option=com_helloworld 頁面總會出現紅色錯誤 ( Error loading component: com_helloworld, 1  *3 ,只要建立 yoursite/components/com_helloworld/helloworld.php 即讀得到該頁面 )
解法:
在英文教程中點選  archive 下載zip檔,該系列每篇教程大部分都有archive可以下載
發現zip檔中的xml檔案是1.6版本的內容,因為這篇的關係 - http://forum.joomla.org/viewtopic.php?f=642&t=773247 所以把內容改成網頁上面的xml檔,並把version="2.5.0" 改成你joomla的版本2.5.x ,看版本可以去後台,登入後畫面下方可以看到版號 - ( 未測試不改xml內容會如何... )
將xml檔案、admin資料夾、site資料夾重新壓縮成zip檔,windows系統勿壓縮成rar檔,否則會出現Unknown Archive Type的錯誤
Unknown Archive Type的錯誤相關解法:
http://www.adonismedia.com/component/k2/item/233-unknown-archive-type-in-joomla-the-solution
最後,將zip檔使用後台Extensions=>Extension Manager: Install 在  Upload Package File 中上傳
(原文: Create a compressed file of this directory or directly download the archive and install it using the extension manager of Joomla. )
最後即可在 /index.php?option=com_helloworld 與 /administrator/index.php?option=com_helloworld 中看到沒有錯誤訊息的component頁面(雖然上傳zip檔後Extension Manager: Install工具仍出現錯誤: JInstaller: :Install: Cannot find XML setup file *2 ,但似乎不影響結果)

其他:
關於JControllerLegacy: http://blog.sina.com.cn/s/blog_ade1969201016aj8.html

***** 20130908_0200 *****
研究 com_helloworld-1.6-part01.zip ( 放在: http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Developing_a_Basic_Component )
直接下載英文教程上的archive中xml為version="1.6.0",測試直接upload可正常使用
helloworld.xml
其中的 name, creationDate, author, copyright, authorEmail, authorUrl, version, description 標籤會存到
aso82_extensions( aso82為當初安裝時系統給的亂數prefix ) 資料表中的manifest_cache欄位,以json格式儲存

{
    "legacy": false,
    "name": "Hello World!",
    "type": "component",
    "creationDate": "November 2009",
    "author": "John Doe",
    "copyright": "Copyright Info",
    "authorEmail": "john.doe@example.org",
    "authorUrl": "http://www.example.org",
    "version": "0.0.1",
    "description": "Description of the Hello World component ...",
    "group": ""
} 

extension的type屬性會存到資料表中的type欄位
( 如何搜到這資料表的: 打開phpmyadmin => 點資料表 => 點搜索 => 將xml的description內容貼到"尋找之文字或數值"input上 => radio選所有文字後搜索 => 即可發現 1 項資料符合 - 於資料表 aso82_extensions )
files標籤的folder屬性為zip檔中資料夾名稱,其下結構與zip檔資料夾下檔案和資料夾結構相同
administration標籤對應到joomla後台
如何移除安裝好的component?
https://kb.siteground.com/how_to_uninstall_a_component_in_joomla_25/
後台 -> Extensions -> Extension Manager -> 打開Manage分頁 -> 下拉選單Select Type選擇Component -> 發現Hello World!在列表中(可點選status上的圖示讓他disable掉,只有前台disabe,後台介面依然還在)
移除component:
勾選Hello World! => 點右上角 uninstall
移除後,前後台頁面都會不見
使用git觀察uninstall Hello World component後,專案中移除了哪些檔案:
#       deleted:    administrator/components/com_helloworld/helloworld.php
#       deleted:    administrator/components/com_helloworld/helloworld.xml  ( 在zip檔中此檔放在根目錄 )
#       deleted:    administrator/components/com_helloworld/index.html
#       deleted:    administrator/components/com_helloworld/sql/index.html
#       deleted:    administrator/components/com_helloworld/sql/updates/index.html
#       deleted:    administrator/components/com_helloworld/sql/updates/mysql/0.0.1.sql
#       deleted:    administrator/components/com_helloworld/sql/updates/mysql/index.html
#       deleted:    components/com_helloworld/helloworld.php
#       deleted:    components/com_helloworld/index.html
ps. 資料庫設定檔在根目錄的 configuration.php 檔案中

***** 20130910_0130 *****
研究 com_helloworld-1.6-part02 ( 放在:http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Adding_a_view_to_the_site_part )
前台 index.php?option=com_helloworld 四隻關鍵檔案呼叫順序依序是:
1. site/helloworld.php
2. site/controller.php
3. site/views/helloworld/view.html.php
4. site/views/helloworld/tmpl/default.php
關於site/helloworld.php -
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import joomla controller library
jimport('joomla.application.component.controller');  //必須,否則會出錯
 
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
// 如欲代不同參數進去,ex. HelloWorld2,在site/controller.php必須新增HelloWorld2的class,因為JController::getInstance 只會抓到site/controller.php這隻檔案
 
// Perform the Request task
$input = JFactory::getApplication()->input;
$controller->execute($input->getCmd('task'));
// 這兩行在zip檔中為一行:$controller->execute(JRequest::getCmd('task')); ,亦可執行

// $controller->bear(); //亦可呼叫自訂函數,需在HelloWorldController類別中新增該函數
 
// Redirect if set by the controller
$controller->redirect();

關於 site/controller.php -
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controller library
jimport('joomla.application.component.controller'); // 這邊註解掉,目前無異狀
 
/**
 * Hello World Component Controller
 */
class HelloWorldController extends JController
{
    //可新增自訂函數
}
// 或新增其他類別,ex. class HelloWorld2Controller extends JController

關於 site/views/helloworld/view.html.php -
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
jimport('joomla.application.component.view');
 
/**
 * HTML View class for the HelloWorld Component
 */
class HelloWorldViewHelloWorld extends JView
{
        // Overwriting JView display method
        function display($tpl = null) 
        {
                // Assign data to the view
                $this->msg = 'Hello World'; // 欲顯示的內容
 
                // Display the view
                parent::display($tpl); // 類似smarty的 dispaly()
        }
}

parent::display($tpl); - 類似smarty的 dispaly(),default.php是預設的,設定在JView物件中(但不知為何 protected $_layout = 'default2'; 這邊修改後,在public function getLayout()仍傳回'default' ),如欲代其他樣板進去ex. 'bear',則必須在tpml資料夾中新增default_bear.php

關於 site/views/helloworld/tmpl/default.php - 類似smarty的tpl內容,寫HTML的地方

***** 20130914_0200 *****
研究 com_helloworld-1.6-part03.zip ( 在 http://docs.joomla.org/Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_03 )
與前一隻zip檔案不同之處是新增了 site/views/helloworld/tmpl/default.xml
使用後台工具上傳zip檔,可以直接上傳,無須移除再上傳
本教程目標是新增一個Menu Item Type(直接連結到前面教程新增的component), 什麼是 Menu Item Type?在後台Menus中的( User Menu, Top, About Joomla, Australian Parks, Main Menu , Fruit Shop )新增或修改時所選擇的Menu Item Type屬性,選擇不同Menu Item Type後會自動刷頁代入網址,儲存時Alias不設定的話會自動代成Menu Title的內容(全小寫)
測試:新增一個Top類型的Menu(選擇自訂的Menu Item Type)
結果:在前台上方選單中新增了一個連結,點進去後是HelloWorld的component
ps. com_helloworld-1.6-part02.zip 教程中有附上 JControllerJView 的文件連結,文件中小圖示代表的意思在這裡,或直接mouseover上去有提示。

***** 20141016 *****
查joomla版本
$ find ./ -name version.php
./libraries/cms/version/version.php
version.php內容:
public $RELEASE = '2.5';
..
public $DEV_LEVEL = '25';
所以版本是2.5.25,亦可在後台登入後的下方看

使用WordBridge套件將wordpress整合到joomla上
去 http://extensions.joomla.org/extensions/authoring-a-content/blog-integration/17095 下載 com_wordbridge_for_joomla_1.6-0.5.zip — Joomla 1.6/1.7/2.5 component (release 0.5) (因為我joomla是2.5.25版本)
安裝方法:
https://github.com/cognidox/WordBridge
1. 登入joomla後台 (http://your.joomla/administrator
2. 選擇 Extensions -> Extension Manager -> Install screen ->  選擇剛剛下載的 com_wordbridge_for_joomla_1.6-0.5.zip  然後點Upload & Install
出現錯誤:
JFolder::create: Could not create directory
原因:
因為當初我的joomla是在windows上做的,現在移到linux上,所以要修改configuration.php設定:
public $log_path = 'C: \\... \joomla/logs'; => public $log_path = '/var/www/html/.../joomla/logs';
public $tmp_path = 'C:\\...\joomla/tmp'; => public $tmp_path = '/var/www/html/.../joomla/tmp';
出現錯誤:
Warning: Failed to move file!
原因:
去後台的site --> System Information --> Directory Permissions --> Status 查是否所有資料夾都Writable
沒有的話改joomla資料夾權限
# chown www-data:username -R joomla
再刷新檢查,可以寫入後就能上傳plugin了
使用Component:
1. 登入joomla後台
2. 使用 Menu Manager新增一個new menu item
3. Menu Item Type選擇 WordBridge -> List of blog entries
4. 在WordBridge Settings 設定 Wordpress blog name為
    a. 如果你的wordpress是放在私人網址上就填:myblog.example.com/wordpress(資料夾下也可)
    b. 放在http://example.wordpress.com/上的話填:example
5. 儲存
6. 在前台點選新的表單後就會出現該wordpress上的內容

***** 20141222 *****
(Joomla 3.3.6)
自訂 HelloWorldViewHelloWorld ( components/com_helloworld/views/helloworld/view.html.php )
中 parent::display($tpl); 的$tpl
ex.
parent::display('test');
則必須新增檔案default_test.php在 components/com_helloworld/views/helloworld/tmpl/default_test.php
由trace libraries/legacy/view/legacy.php 中的function display和 function loadTemplate 中得知
更多請參考 官方 JViewLegacy 文件

***** 20150126 *****
存取joomla資料庫
http://developer.joomla123.com.tw/com/backend-component/edit-and-form.html
INSERT - 在com_contact/controllers/contact.php 的submit()內有效:
$db = JFactory::getDBO();
$sql = "INSERT INTO #__helloworld (`id`, `greeting`, `catid`, `params`) VALUES (NULL, 'tedbear', '0', '')";
$db->setQuery($sql);
$db->execute();
SELECT -
$db = JFactory::getDbo();
// Or using $db = $this->_db;
$sql = "SELECT * FROM #__blog_articles";
$db->setQuery($sql);
$results = $db->loadObjectList();
ps. 範例blog 元件
https://github.com/asika32764/joomla-blog-component-example


解決DS沒有定義的bug
因為DS常數已經被移除了。要用的是DIRECTORY_SEPARATOR
解法1. 
com_xxx/xxx.php加入這行:
if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
解法2. 
安裝這個套件:
http://digitaldisseny.com/en/joomla-extensions/solve-undefined-ds-constant-joomla-3-error
github plg_sys_dsconstant:https://github.com/digitaldisseny/plg_sys_dsconstant/

1 則留言: