BloggerAds廣告

相關文章

2015年6月26日 星期五

php pass data to include_once() require_once()

The following code shows how to pass params to included files in php
it works also in the following functions:
include()
include_once()
require()
require_once()


application.php
Using an Associative array to carry variables would be an ideal option.
<?php
$m = new Main();

$items = array(
 'name'=> 'John Doe',
 'items'=>array('stone', 'knife', 'card', 'etc...')
);

$m->loadViewWithParams('item_list_view.php', $items);
?>

Main.php
For variables which visibles to the line above the include(), they also visibles to the included file.
We simply create variables just above the include() just the way that many people do so.
Since we've passed an associative array to loadViewWithParams(), we will break the array into variables in runtime.
<?php
class Main {
/**
*
*@param $path string the file path to load.
*@param $params array an associative array which carry data to the loaded file.
*/
  public function loadViewWithParams($path, $params = array()){
    //we use a foreach to parse the array to variables
    foreach ($params as $key => $value ) {
      $$key = $value;
    }

    include_once($path);
  }
}
?>

item_list_view.php
consider the application.php above
the loadViewWithParams() method converted the array into variables
now both $name and $item were passed to the included file
<div>
 <h1>Welcome, <?php echo $name; ?> </h1>
 here are your items
 <ul>
  <?php foreach($myItemList as $item): ?>
  <li><?php echo $item; ?></li>
  <?php endforeach; ?>
 <ul>
</div>

2015年3月30日 星期一

Joomla must-have installation list

This is the list that i find that it is a MUST-HAVE extensions for starting a Joomla project:
(last review: 20th July, 2015)

  • K2 (Component, Plugin, Module)
    This is a replacement of original Joomla article system which provide you a more flexible way to create content.

    K2 comes with some modules such as k2_content to let you display your k2 items in various way you like.
  • Multiple-images-for-k2 (Plugin)
    Default, each k2 items can only insert 1 image, it enables K2 to insert more than 1 image per item.
  • Flexi Custom Code (Module)
    It is a complete replacement of the built-in sucky Custom-HTML module. Say goodbye the Custom-HTML module~~. Now you can use php, css and js in your custom module WITHIN THE JOOMLA FRAMEWORK.

    As i introduced in my previous article, it saves your life in case of your Joomla project is full of custom requirements which cannot be done in normal way.

  • Fabrik (Component, Plugin, Module)
    Fabrik gives you the power to create forms and tables that run inside Joomla without requiring knowledge of mySQL and PHP.
  • Blank Component (Component)
    Simply let you create a blank module only section without creating a zero article category

  • Modules Anywhere (Plugin, Editor button plugin)
    With this plugin, you can force display any module to anywhere you like. for example sometimes you would like to force display a module in another location... such as.. k2 Item...
  • ACL Manager (paid) (Component)
    The complete replacement of built-in ACL manager. It makes the ACL interface much easier to use. The built-in ACL system is very confuse and hard to use. Although it is not free, it's worth to pay.
  • Advanced Module Manager (Component, Plugin)
    A replacement of original module manager. It provide a more detail way to manage your modules. The free version is good enough.
i will keep updating this list once i discovered any new useful extensions. Hope those extensions helps you to develop Joomla site

2015年3月18日 星期三

Flexi Custom Code Joomla module

Joomla is good for quick cms project but once the client needs special requirement, welcome to the hell~~. (Yeh actually I'm wandering at the hell now . . . . .)

Im working on a project, for some reason, most of data were not retrieve from K2 items table nor Joomla article table but few another custom tables.

in this case, obviously, non of modules in the world fit our needs.

ok~ in short, the problem is:
1. Our content were not from Joomla Article nor K2 Items (for some reason, dont ask me why)
2. We need to migrate the whole Joomla site's module/plugins to support our content table

The built-in Custom HTML module is a joke. it Just simply STATIC HTML and thats it.

Plugin can extend your joomla site in many ways but you have no way to decide where your plugin should display.

here you're few solutions:



  1. Modify existing extensions

    Since the data source is not related to K2 items nor Joomla article now, we are free to modify the existing module to migrate our custom table, or simply download any modules with cool effect and ignores if it supports K2 or not.


    This solution will fits 1 requirement. what if another one? I mean use the same layout with completely different source. Would u like to add N settings in the module xml file or duplicate the module?


    Also modifying an module will makes the module setting useless since we're no need to/unable to care about them. it makes your module chaos --- What if i need this module to display normal k2 items in future?

  2. Sub-templating the mod_k2_content

    K2 comes with a cool module k2 content.  This module have a complete settings to let you filter your k2 items in whatever you want. and the coolest setting of k2 content is sub-templating.

    it lets you create custom layout of K2 items in any way you like

    Sounds cool eh? yes it is IF OUR DATA SOURCE ARE FROM K2 ITEMS.

    with this solution, you will need to create tons of subtemplates and you will also need to create helpers for each template. And the same cons -- it will ignores all setting of the module because you dont need to use them.
  3. write your own

    it should be an ideal solution if time is not an issue.
so what im going to show you today is:
Flexi Custom Code I can say this is a robust version of built-in Custom HTML
This is a module to let you write your own html, php, js, css
It can use all Joomla classes such as JURI:base(), JFactory::getDBO()
You can even use exit() in this module
(the php include() function seems not work so well in this module)
the only setting of Flexi Custom Code is your source code. Feel free to write your own layout and feel free to call any fancy query and call from any other DB tables
Just think it as you write with plain php page~