Showing posts with label Pyrocms. Show all posts
Showing posts with label Pyrocms. Show all posts

Thursday, May 3, 2012

Working with arrays in pyrocms plugins

Hi guys, I am writing this post for one of my cool blog reader. He posted a comment that how we can return arrays from plugins to plugin view files and then how we can loop through and display the values of that array.

Pyrocms is very cool in handling this type of thing because it has a very strong template engine already built-in its codeignitor package. In order to explain how to use array in pyrocms plugin, i will take the same "example" plugin which I explained in this post http://our-knowledge-base.blogspot.com/2012/04/how-to-develop-custom-plugin-in-pyrocms.html.

Adding another function:

Open "example" plugin code and put the following function some where in that class.
 <?php  
 public function myposts()  
 {  
           $plugin_data = array();  
           $plugin_data[] = array(  
                                    'value'          => "Post # 1 value",  
                                    'title'          => 'Post # 1 title'  
                               );  
           $plugin_data[] = array(  
                                    'value'          => "Post # 2 value",  
                                    'title'          => 'Post # 2 title'  
                               );  
           $plugin_data[] = array(  
                                    'value'          => "Post # 3 value",  
                                    'title'          => 'Post # 3 title'  
                               );  
           return $plugin_data;  
      }  
 ?>  

so after adding this function whole plugin code will look like this,
1:  <?php defined('BASEPATH') OR exit('No direct script access allowed');  
2:  /**  
3:   * Example Plugin  
4:   *  
5:   * Quick plugin to demonstrate how things work  
6:   *  
7:   * @package          PyroCMS  
8:   * @author          PyroCMS Dev Team  
9:   * @copyright     Copyright (c) 2009 - 2010, PyroCMS  
10:   *  
11:   */  
12:  class Plugin_Example extends Plugin  
13:  {  
14:       /**  
15:        * Hello  
16:        *  
17:        * Usage:  
18:        * {{ example:hello }}  
19:        *  
20:        * @param     array  
21:        * @return     array  
22:        */  
23:       function hello()  
24:       {  
25:            $name = $this->attribute('name', 'World');  
26:            return 'Hello '.$name.'!';  
27:       }  
28:   
29:  
30:
31:   public function myposts()  
32:   {  
33:         $plugin_data = array();  
34:         $plugin_data[] = array(  
35:                                    'value'          => "Post # 1 value",  
36:                                    'title'          => 'Post # 1 title'  
37:                               );  
38:         $plugin_data[] = array(  
39:                                    'value'          => "Post # 2 value",  
40:                                    'title'          => 'Post # 2 title'  
41:                               );  
42:         $plugin_data[] = array(  
43:                                    'value'          => "Post # 3 value",  
44:                                    'title'          => 'Post # 3 title'  
45:                               );  
46:          return $plugin_data;  
47:      }  
48:  }  
49:  /* End of file example.php */

How to use this?
Using this is very simple. You just have to paste following code in view file. It will show post titles in the form of a list.
 {{ example:myposts }}  
     <strong>{{ name }}:</strong> {{ value }}<br />  
 {{ /example:myposts }}  

Although this is a very simple explanation of how to handle arrays in pyrocms, but after ready and understanding this example, you can easily modify this or even can develop your own complex plugin.

Please feel to post comments on this.

Thanks

Tuesday, April 17, 2012

How to develop a custom plugin in pyrocms


Today I am going to tell you how we can develop our own custom plug-in in pyrocms. In pyrocms whenever we edit some theme, or some view files, sometimes you will see some tags like {{ session:data name="foo" value="bar" }}. These are actually pyrocms plug-ins.

What is a plug-in?

In computing, a plug-in (or plug-in) is a set of software components that adds specific abilities to a larger software application.

In pyrocms there are two types of plug-in

  1. Standalone plug-in
  2. Modular plug-in

Standalone Plug-in:

Stand alone is a general plugin which is not necessarily dependent to other modules etc, like Google map, a simple twitter application etc. In pyrocms standalone plug-in are location in addons/plugins/.php

Modular plug-in:

Modular plug-in is actually a part of module which we already have developed. It actually adds more functionality in our existing module, that’s why it is located in the same module directory like addons/modules//plugin.php

How to develop this?

Create a file in addons/shared_addons/plugins/ directory with name example,php. And then put the following code in it and save.


1:  <?php defined('BASEPATH') OR exit('No direct script access allowed');  
2:  /**  
3:   * Example Plugin  
4:   *  
5:   * Quick plugin to demonstrate how things work  
6:   *  
7:   * @package          PyroCMS  
8:   * @author          PyroCMS Dev Team  
9:   * @copyright     Copyright (c) 2009 - 2010, PyroCMS  
10:   *  
11:   */  
12:  class Plugin_Example extends Plugin  
13:  {  
14:       /**  
15:        * Hello  
16:        *  
17:        * Usage:  
18:        * {{ example:hello }}  
19:        *  
20:        * @param     array  
21:        * @return     array  
22:        */  
23:       function hello()  
24:       {  
25:            $name = $this->attribute('name', 'World');  
26:            return 'Hello '.$name.'!';  
27:       }  
28:  }  
29:  /* End of file example.php */  

How to use this?

Using this plugin is very simple. just put {{ example:hello }} tag in you them or in any view file and save it. By refreshing your page you will see "Hello World!" as output.

Please feel free to post your comments or queries.

Monday, April 9, 2012

Pyrocms - Creating hello world module in pyrocms

Custom module development :-

Hi all, today i am gonna show you how you can create a simple "hello world" module in pyrocms. You can do so by following some simple steps mentioned in this article.

Pyrocms - Step by step tutorial to create widget in pyrocms

Hi all, today i am going to tell you how to create a pyrocms widget in some easy steps. Widgets are a small program to show some text or some login form etc on your website. The widget we are going to develop in this tutorial, also outputs some simple text on sidebar. So here are the steps,