Drupal
Steps to display the Twitter Feed in a Drupal Block
In this article, we are going to discuss about How to display the Twitter Feeds in Drupal Block. By using this, we can display that Twitter feed anywhere in the site. There are many different Twitter options out there but most have a couple of limitations. The limitations are below
We are going to create much simpler way to show tweets in a block on your site. Twitter Block Drupal module is used to display the twitter feeds in our site.
Step 1 : Installing Twitterblock module
Step 2 : Placing the Twitter Feed in a Block
Click "Save Block", publish the block and check to see how it looks on your site. Twitter feeds will display on the site.
- They post tweets as nodes rather than in a block.
- If they post to a block, they require very complex setups normally involving creating Views.
We are going to create much simpler way to show tweets in a block on your site. Twitter Block Drupal module is used to display the twitter feeds in our site.
Step 1 : Installing Twitterblock module
- Click Here to download the Twitter block module.
- Extract the files into a folder on your desktop. The folder will be called "twitterblock".
- Login to your site's files via FTP and navigate to /sites/default/. If there isn't a folder called /modules/ here, create one.
- Upload the "twitterblock" folder to /sites/default/modules/
- Go to Administrator >> Modules. Check the box in-front of the "Twitter Block" and click Save Configuration button at the bottom of the page.
Step 2 : Placing the Twitter Feed in a Block
- Go to Administrator >> Structure >> Blocks. Scroll down to find Twitter Block.
- Click "Configure" next to the block and enter your Twitter username and password:
Click "Save Block", publish the block and check to see how it looks on your site. Twitter feeds will display on the site.
PHP CMS Frameworks
March 31, 2014
Read more →
Joomla
Steps to resolve the broken Captcha in Joomla 2.5 and 3
In this article, we are going to discuss about How to solve/fix the broken captcha in Joomla 2.5 and Joomla 3. A CAPTCHA is a program that protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot. Joomla 2.5 and Joomla 3 contact forms comes with the default captcha function.
Using Captchas can greatly reduce the amount of spam you receive.
However, many of these forms (including mine) stopped working because Google changed the URL used for ReCaptchas.
This is mostly impacting Joomla 2.5 and 3.0+ sites at the minimum. This fix will be included in the next Joomla 3 release but in the meantime, it's not good to have a broken contact form.
Here's the fix for Joomla 2.5 and 3 sites
The fix is taken from this joomla.org doc.
Go to plugins/captcha/recaptcha/recaptcha.php and change:
line 22 (or thereabouts) to the new RECAPTCHA_API_SERVER URL of 'http://www.google.com/recaptcha/api'
line 24 (or thereabouts) to the new RECAPTCHA_VERIFY_SERVER URL of 'www.google.com'
line 129 (or thereabouts) to the new RECAPTCHA_VERIFY_SERVER value of '/recaptcha/api/verify'
You will need FTP access to make this change, or perhaps your hosting control panel has a file manager that lets you edit files. In either case be sure to make a backup of the existing recaptcha.php file before making the recommended edits.
Using Captchas can greatly reduce the amount of spam you receive.
However, many of these forms (including mine) stopped working because Google changed the URL used for ReCaptchas.
This is mostly impacting Joomla 2.5 and 3.0+ sites at the minimum. This fix will be included in the next Joomla 3 release but in the meantime, it's not good to have a broken contact form.
Here's the fix for Joomla 2.5 and 3 sites
The fix is taken from this joomla.org doc.
Go to plugins/captcha/recaptcha/recaptcha.php and change:
line 22 (or thereabouts) to the new RECAPTCHA_API_SERVER URL of 'http://www.google.com/recaptcha/api'
line 24 (or thereabouts) to the new RECAPTCHA_VERIFY_SERVER URL of 'www.google.com'
line 129 (or thereabouts) to the new RECAPTCHA_VERIFY_SERVER value of '/recaptcha/api/verify'
You will need FTP access to make this change, or perhaps your hosting control panel has a file manager that lets you edit files. In either case be sure to make a backup of the existing recaptcha.php file before making the recommended edits.
PHP CMS Frameworks
March 27, 2014
Read more →
CodeIgniter
Drag and Drop Shopping Cart Using CodeIgniter Cart and ExtJS
In this article, we are going to discuss about How to create the Drag and Drop shopping cart application using CodeIgniter Cart and ExtJS. We are using MYSQL for storing the product data. Here I am going to explain in step by step detail to create the Drag and Drop shopping cart app using CI cart and ExtJS.
Step 1 : Database Preparation
Create a database named "ci_extjs_cart" or with other name that you desired then create the table.
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT NULL,
`price` varchar(32) DEFAULT NULL,
`image` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
And these are the sample datas (I already included the sample image on the code that you can download)
INSERT INTO `products` (`id`, `name`, `price`, `image`) VALUES
(1, 'HP - 20 Inch Widescreen Flat-Panel LCD Monitor', '169', 'hp.jpg'),
(2, 'Gateway - 20 Inch Widescreen Flat-Panel LCD Monitor', '159', 'gateway.jpg'),
(3, 'Apple - 30 Flat-Panel TFT-LCD Monitor', '1799', 'apple.jpg'),
(4, 'Acer - 24 Inch Flat-Panel LED-LCD Monitor', '299', 'acer.jpg'),
(5, 'Asus - 24 Inch Widescreen Flat-Panel LCD Monitor', '249', 'asus.jpg');
Step 2 : CodeIgniter Configuration
First time to get hand dirty with a framework is to set all the config file (in folder: "application/config/"). The four files that we have to configure are:
config.php
$config['base_url'] = "http://localhost/ci_extjs_cart/";
database.php
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "admin";
$db['default']['database'] = "ci_extjs_cart";
$db['default']['dbdriver'] = "mysql";
routes.php
$route['default_controller'] = "product";
The default controller is set to product controller, in this step we have not create the controller yet.
autoload.php
$autoload['libraries'] = array('database', 'session');
$autoload['helper'] = array('url');
Step 3 : ExtJS configuration on CodeIgniter
Like always, include the ExtJS file on separate folder from Codeigniter (CI).
Step 4 : Controller and View creation
The Controller, create a file product.php inside the controllers folder, the very usual method on the controller is the contrustion and the index method, in the construction method the codeigniter cart class loaded.
<?php
class Product extends Controller {
public function __construct()
{
parent::Controller();
$this->load->library('cart');
}
public function index()
{
$this->load->view('product/index');
}
}
The View, create the view file inside views folder "index.php", the first step to preparing the view is to preparing the HTML layout, include the ExtJS file, and create a basic layout style in CSS.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/js/ext/resources/css/ext-all.css"/>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/ext/ext-all.js"></script>
<!-- product data view style -->
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/js/ext/ux/data-view.css"/>
<script type="text/javascript">
var BASE_URL = '<?php echo site_url(); ?>/';
Ext.onReady(function() {
});
</script>
<title>Extjs Image Gallery Using DataView</title>
<style type="text/css">
body {
padding: 20px;
margin: 0 auto;
}
#container {
padding: 10px;
background: #e3e3e3;
border: 1px solid #d3d3d3;
margin: 0 auto;
text-align: left;
width: 630px;
}
#top {
}
#bottom {
margin-top: 10px;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="container">
<div id="top"></div>
<div id="bottom"></div>
</div>
</body>
</html>
The Ext.ready function is still empty, inside this function all the ExtJS component will be placed, and I always using BASE_URL value that have value of site_url(); function, to make it easier when accessing a url.
Step 5 : Get Product List
The Controller, this is the method the get all the product data, and sending the data as json format.
public function ext_get_all()
{
$query = $this->db->get('products');
$product_arr = array();
foreach($query->result() as $key => $data)
{
$product_arr[] = array(
'id' => $data->id,
'name' => $data->name,
'price' => $data->price,
'image' => $data->image
);
}
echo json_encode(array('products' => $product_arr));
}
The View, this is the code for creating the product list in dataview, and a function to make the dataview draggable.
var proxyProduct = new Ext.data.HttpProxy({
url: BASE_URL + 'product/ext_get_all', method: 'POST'
});
var strProduct = new Ext.data.JsonStore({
proxy: proxyProduct,
root: 'products',
fields: [
'id', 'name', 'price', 'image'
]
});
strProduct.load();
var tplProduct = new Ext.XTemplate(
'<tpl for=".">',
'<div class="thumb-wrap" id="{name}">',
'<div class="thumb"><img src="http://localhost/ci_extjs_cart/assets/img/{image}" title="{name}"></div>',
'<span class="name">{name}</span>',
'<div class="price">$ {price}</div></div>',
'</tpl>',
'<div class="x-clear"></div>'
);
var dvProduct = new Ext.DataView({
autoScroll: true, store: strProduct, tpl: tplProduct,
autoHeight: false, height: 200, multiSelect: false,
overClass: 'x-view-over', itemSelector: 'div.thumb-wrap',
emptyText: 'No product to display',
style: 'border:1px solid #99BBE8;',
listeners: {
render: initializeItemDragZone
}
});
function initializeItemDragZone(v) {
v.dragZone = new Ext.dd.DragZone(v.getEl(), {
getDragData: function(e) {
var sourceEl = e.getTarget(v.itemSelector, 10);
if (sourceEl) {
d = sourceEl.cloneNode(true);
d.id = Ext.id();
return v.dragData = {
sourceEl: sourceEl,
repairXY: Ext.fly(sourceEl).getXY(),
ddel: d,
itemData: v.getRecord(sourceEl).data
}
}
},
getRepairXY: function() {
return this.dragData.repairXY;
}
});
}
var panelProduct = new Ext.Panel({
id: 'images-view',
frame: true,
width: 620,
autoHeight: true,
title: 'Product DataView',
style: 'margin:0 auto;',
items: [dvProduct]
});
panelProduct.render('top');
Step 6 : Create The Cart (Using EditorGridPanel)
The Controller, we will create some basic function to manipulating the cart I try to explain them in the separate way, but still in the same controller
6.1 Get All Cart
public function ext_get_cart()
{
if ($this->cart->total_items() != 0)
{
foreach($this->cart->contents() as $product)
{
$cart_arr[] = array(
'rowid' => $product['rowid'],
'id' => $product['id'],
'qty' => $product['qty'],
'name' => $product['name'],
'price' => $product['price'],
'subtotal' => $product['subtotal']
);
}
$cart_arr[] = array(
'rowid' => '',
'id' => '',
'qty' => '',
'name' => '',
'price' => '<b>Total:</b>',
'subtotal' => '<b>'.$this->cart->total().'</b>'
);
echo json_encode(array('cart' => $cart_arr));
}
else
{
$cart_arr[] = array();
echo json_encode(array('cart' => $cart_arr));
}
}
This function is to getting all the available product in the cart in the session, if the cart is not empty then just loop through the cart function "$this->cart->contents()" and put this to array. I add another array to showing the total value from the cart, this will be treated different in the ExtJS grid, and send it as json format
6.2 Add a Product to Cart
public function ext_add_cart()
{
if ($_POST['rowid'] == '')
{
$data = array(
'id' => $_POST['id'],
'qty' => 1,
'price' => $_POST['price'],
'name' => $_POST['name']
);
$this->cart->insert($data);
}
else
{
$data = array(
'rowid' => $_POST['rowid'],
'qty' => intval($_POST['qty']) + 1
);
$this->cart->update($data);
}
echo '{success:true, total: "'.$this->cart->total().'"}';
}
You must be can see in the add cart function there are conditional statement that updating the cart instead insert a new data to cart, well this is to handle if a user adding the product that already available on the cart, so the cart must be updating only the quantity.
6.3 Update a Product Quantity
public function ext_update_cart()
{
$data = array(
'rowid' => $_POST['rowid'],
'qty' => $_POST['qty']
);
$this->cart->update($data);
echo '{success:true}';
}
This function is to updating a product quantity on the cart, I make the quantity editable on the grid so the user can easy put the number of a product that he desired, and to deleting a product from cart the user have to put zero value on the quantity editable grid.
6.4 Clear Cart
public function ext_clear_cart()
{
$this->cart->destroy();
echo '{success:true}';
}
Well nothing really hard in this function, using "$this->cart->destroy()" all the cart clear.
6.5 The Cart
var strCart = new Ext.data.JsonStore({
root: 'cart',
fields: [
'rowid', 'id', 'qty', 'name', 'price', 'subtotal'
],
proxy: new Ext.data.HttpProxy({
url: BASE_URL + 'product/ext_get_cart', method: 'POST'
})
});
strCart.load();
var cb_select = new Ext.grid.CheckboxSelectionModel();
function showDollar(val) {
if (val == '' || val == '<b>Total:</b>') {
return val;
}
else {
return '$ ' + val;
}
}
var panelCart = new Ext.grid.EditorGridPanel({
frame: true, border: true, stripeRows: true,
store: strCart, loadMask: true, title: 'Your Cart (Drag Here)',
style: 'margin:0 auto;font-size:13px;',
height: 220, width: 500, sm: cb_select,
columns: [{
header: 'rowid',
dataIndex: 'rowid',
hidden: true,
hideable: false
}, {
header: 'id',
dataIndex: 'id',
hidden: true,
hideable: false
}, {
header: "Product Name",
dataIndex: 'name',
sortable: true,
width: 280
}, {
header: "Qty",
align: 'center',
width: 40,
dataIndex: 'qty',
menuDisabled: true,
editor: new Ext.form.TextField({
allowBlank: false,
vtype: 'alphanum',
id: 'qtyField'
})
}, {
header: "Price",
dataIndex: 'price',
sortable: true,
align: 'right',
renderer: showDollar,
width: 80
}, {
header: "Subtotal",
sortable: true,
align: 'right',
width: 80,
renderer: showDollar
}],
listeners: {
'afteredit': function() {
var sm = panelCart.getSelectionModel().getSelections();
panelCart.getSelectionModel().clearSelections();
Ext.Ajax.request({
method: 'POST',
url: BASE_URL + 'product/ext_update_cart',
params: {
rowid: sm[0].get('rowid'),
qty: Ext.getCmp('qtyField').getValue()
},
success: function() {
strCart.load();
}
});
}
},
buttons: [{
text: 'Clear Cart',
handler: function() {
Ext.Ajax.request({
url: BASE_URL + 'product/ext_clear_cart',
method: 'POST',
success: function() {
strCart.load();
}
});
}
}, {
text: 'Check Out',
handler: function() {
}
}]
});
panelCart.render('bottom');
var formPanelDropTargetEl = panelCart.getView().scroller.dom;
var formPanelDropTarget = new Ext.dd.DropTarget(formPanelDropTargetEl, {
notifyDrop : function(ddSource, e, data){
panelCart.getSelectionModel().selectAll();
var sm = panelCart.getSelectionModel().getSelections();
panelCart.getSelectionModel().clearSelections();
data.itemData.rowid = '';
for (i=0; i<=sm.length-1; i++) {
if (sm[i].get('id') == data.itemData.id) {
data.itemData.rowid = sm[i].get('rowid');
data.itemData.qty = sm[i].get('qty');
// so can out from loop
i = sm.length;
}
}
Ext.Ajax.request({
url: BASE_URL + 'product/ext_add_cart',
method: 'POST',
params: {
'id': data.itemData.id,
'price': data.itemData.price,
'name': data.itemData.name,
'rowid': data.itemData.rowid,
'qty': data.itemData.qty
},
success: function() {
strCart.load();
}
});
return(true);
}
});
That's all for the Cart features, there is CheckboxSelectionModel component, this component is to check whether the product is already on the cart, you can see it used on notifyDrop inside the dropTarget you have to add, the expected result is something like this.
To download full source of this application Click Here
Step 1 : Database Preparation
Create a database named "ci_extjs_cart" or with other name that you desired then create the table.
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT NULL,
`price` varchar(32) DEFAULT NULL,
`image` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
And these are the sample datas (I already included the sample image on the code that you can download)
INSERT INTO `products` (`id`, `name`, `price`, `image`) VALUES
(1, 'HP - 20 Inch Widescreen Flat-Panel LCD Monitor', '169', 'hp.jpg'),
(2, 'Gateway - 20 Inch Widescreen Flat-Panel LCD Monitor', '159', 'gateway.jpg'),
(3, 'Apple - 30 Flat-Panel TFT-LCD Monitor', '1799', 'apple.jpg'),
(4, 'Acer - 24 Inch Flat-Panel LED-LCD Monitor', '299', 'acer.jpg'),
(5, 'Asus - 24 Inch Widescreen Flat-Panel LCD Monitor', '249', 'asus.jpg');
Step 2 : CodeIgniter Configuration
First time to get hand dirty with a framework is to set all the config file (in folder: "application/config/"). The four files that we have to configure are:
config.php
$config['base_url'] = "http://localhost/ci_extjs_cart/";
database.php
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "admin";
$db['default']['database'] = "ci_extjs_cart";
$db['default']['dbdriver'] = "mysql";
routes.php
$route['default_controller'] = "product";
The default controller is set to product controller, in this step we have not create the controller yet.
autoload.php
$autoload['libraries'] = array('database', 'session');
$autoload['helper'] = array('url');
Step 3 : ExtJS configuration on CodeIgniter
Like always, include the ExtJS file on separate folder from Codeigniter (CI).
Step 4 : Controller and View creation
The Controller, create a file product.php inside the controllers folder, the very usual method on the controller is the contrustion and the index method, in the construction method the codeigniter cart class loaded.
<?php
class Product extends Controller {
public function __construct()
{
parent::Controller();
$this->load->library('cart');
}
public function index()
{
$this->load->view('product/index');
}
}
The View, create the view file inside views folder "index.php", the first step to preparing the view is to preparing the HTML layout, include the ExtJS file, and create a basic layout style in CSS.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/js/ext/resources/css/ext-all.css"/>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/ext/ext-all.js"></script>
<!-- product data view style -->
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/js/ext/ux/data-view.css"/>
<script type="text/javascript">
var BASE_URL = '<?php echo site_url(); ?>/';
Ext.onReady(function() {
});
</script>
<title>Extjs Image Gallery Using DataView</title>
<style type="text/css">
body {
padding: 20px;
margin: 0 auto;
}
#container {
padding: 10px;
background: #e3e3e3;
border: 1px solid #d3d3d3;
margin: 0 auto;
text-align: left;
width: 630px;
}
#top {
}
#bottom {
margin-top: 10px;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="container">
<div id="top"></div>
<div id="bottom"></div>
</div>
</body>
</html>
The Ext.ready function is still empty, inside this function all the ExtJS component will be placed, and I always using BASE_URL value that have value of site_url(); function, to make it easier when accessing a url.
Step 5 : Get Product List
The Controller, this is the method the get all the product data, and sending the data as json format.
public function ext_get_all()
{
$query = $this->db->get('products');
$product_arr = array();
foreach($query->result() as $key => $data)
{
$product_arr[] = array(
'id' => $data->id,
'name' => $data->name,
'price' => $data->price,
'image' => $data->image
);
}
echo json_encode(array('products' => $product_arr));
}
The View, this is the code for creating the product list in dataview, and a function to make the dataview draggable.
var proxyProduct = new Ext.data.HttpProxy({
url: BASE_URL + 'product/ext_get_all', method: 'POST'
});
var strProduct = new Ext.data.JsonStore({
proxy: proxyProduct,
root: 'products',
fields: [
'id', 'name', 'price', 'image'
]
});
strProduct.load();
var tplProduct = new Ext.XTemplate(
'<tpl for=".">',
'<div class="thumb-wrap" id="{name}">',
'<div class="thumb"><img src="http://localhost/ci_extjs_cart/assets/img/{image}" title="{name}"></div>',
'<span class="name">{name}</span>',
'<div class="price">$ {price}</div></div>',
'</tpl>',
'<div class="x-clear"></div>'
);
var dvProduct = new Ext.DataView({
autoScroll: true, store: strProduct, tpl: tplProduct,
autoHeight: false, height: 200, multiSelect: false,
overClass: 'x-view-over', itemSelector: 'div.thumb-wrap',
emptyText: 'No product to display',
style: 'border:1px solid #99BBE8;',
listeners: {
render: initializeItemDragZone
}
});
function initializeItemDragZone(v) {
v.dragZone = new Ext.dd.DragZone(v.getEl(), {
getDragData: function(e) {
var sourceEl = e.getTarget(v.itemSelector, 10);
if (sourceEl) {
d = sourceEl.cloneNode(true);
d.id = Ext.id();
return v.dragData = {
sourceEl: sourceEl,
repairXY: Ext.fly(sourceEl).getXY(),
ddel: d,
itemData: v.getRecord(sourceEl).data
}
}
},
getRepairXY: function() {
return this.dragData.repairXY;
}
});
}
var panelProduct = new Ext.Panel({
id: 'images-view',
frame: true,
width: 620,
autoHeight: true,
title: 'Product DataView',
style: 'margin:0 auto;',
items: [dvProduct]
});
panelProduct.render('top');
Step 6 : Create The Cart (Using EditorGridPanel)
The Controller, we will create some basic function to manipulating the cart I try to explain them in the separate way, but still in the same controller
6.1 Get All Cart
public function ext_get_cart()
{
if ($this->cart->total_items() != 0)
{
foreach($this->cart->contents() as $product)
{
$cart_arr[] = array(
'rowid' => $product['rowid'],
'id' => $product['id'],
'qty' => $product['qty'],
'name' => $product['name'],
'price' => $product['price'],
'subtotal' => $product['subtotal']
);
}
$cart_arr[] = array(
'rowid' => '',
'id' => '',
'qty' => '',
'name' => '',
'price' => '<b>Total:</b>',
'subtotal' => '<b>'.$this->cart->total().'</b>'
);
echo json_encode(array('cart' => $cart_arr));
}
else
{
$cart_arr[] = array();
echo json_encode(array('cart' => $cart_arr));
}
}
This function is to getting all the available product in the cart in the session, if the cart is not empty then just loop through the cart function "$this->cart->contents()" and put this to array. I add another array to showing the total value from the cart, this will be treated different in the ExtJS grid, and send it as json format
6.2 Add a Product to Cart
public function ext_add_cart()
{
if ($_POST['rowid'] == '')
{
$data = array(
'id' => $_POST['id'],
'qty' => 1,
'price' => $_POST['price'],
'name' => $_POST['name']
);
$this->cart->insert($data);
}
else
{
$data = array(
'rowid' => $_POST['rowid'],
'qty' => intval($_POST['qty']) + 1
);
$this->cart->update($data);
}
echo '{success:true, total: "'.$this->cart->total().'"}';
}
You must be can see in the add cart function there are conditional statement that updating the cart instead insert a new data to cart, well this is to handle if a user adding the product that already available on the cart, so the cart must be updating only the quantity.
6.3 Update a Product Quantity
public function ext_update_cart()
{
$data = array(
'rowid' => $_POST['rowid'],
'qty' => $_POST['qty']
);
$this->cart->update($data);
echo '{success:true}';
}
This function is to updating a product quantity on the cart, I make the quantity editable on the grid so the user can easy put the number of a product that he desired, and to deleting a product from cart the user have to put zero value on the quantity editable grid.
6.4 Clear Cart
public function ext_clear_cart()
{
$this->cart->destroy();
echo '{success:true}';
}
Well nothing really hard in this function, using "$this->cart->destroy()" all the cart clear.
6.5 The Cart
var strCart = new Ext.data.JsonStore({
root: 'cart',
fields: [
'rowid', 'id', 'qty', 'name', 'price', 'subtotal'
],
proxy: new Ext.data.HttpProxy({
url: BASE_URL + 'product/ext_get_cart', method: 'POST'
})
});
strCart.load();
var cb_select = new Ext.grid.CheckboxSelectionModel();
function showDollar(val) {
if (val == '' || val == '<b>Total:</b>') {
return val;
}
else {
return '$ ' + val;
}
}
var panelCart = new Ext.grid.EditorGridPanel({
frame: true, border: true, stripeRows: true,
store: strCart, loadMask: true, title: 'Your Cart (Drag Here)',
style: 'margin:0 auto;font-size:13px;',
height: 220, width: 500, sm: cb_select,
columns: [{
header: 'rowid',
dataIndex: 'rowid',
hidden: true,
hideable: false
}, {
header: 'id',
dataIndex: 'id',
hidden: true,
hideable: false
}, {
header: "Product Name",
dataIndex: 'name',
sortable: true,
width: 280
}, {
header: "Qty",
align: 'center',
width: 40,
dataIndex: 'qty',
menuDisabled: true,
editor: new Ext.form.TextField({
allowBlank: false,
vtype: 'alphanum',
id: 'qtyField'
})
}, {
header: "Price",
dataIndex: 'price',
sortable: true,
align: 'right',
renderer: showDollar,
width: 80
}, {
header: "Subtotal",
sortable: true,
align: 'right',
width: 80,
renderer: showDollar
}],
listeners: {
'afteredit': function() {
var sm = panelCart.getSelectionModel().getSelections();
panelCart.getSelectionModel().clearSelections();
Ext.Ajax.request({
method: 'POST',
url: BASE_URL + 'product/ext_update_cart',
params: {
rowid: sm[0].get('rowid'),
qty: Ext.getCmp('qtyField').getValue()
},
success: function() {
strCart.load();
}
});
}
},
buttons: [{
text: 'Clear Cart',
handler: function() {
Ext.Ajax.request({
url: BASE_URL + 'product/ext_clear_cart',
method: 'POST',
success: function() {
strCart.load();
}
});
}
}, {
text: 'Check Out',
handler: function() {
}
}]
});
panelCart.render('bottom');
var formPanelDropTargetEl = panelCart.getView().scroller.dom;
var formPanelDropTarget = new Ext.dd.DropTarget(formPanelDropTargetEl, {
notifyDrop : function(ddSource, e, data){
panelCart.getSelectionModel().selectAll();
var sm = panelCart.getSelectionModel().getSelections();
panelCart.getSelectionModel().clearSelections();
data.itemData.rowid = '';
for (i=0; i<=sm.length-1; i++) {
if (sm[i].get('id') == data.itemData.id) {
data.itemData.rowid = sm[i].get('rowid');
data.itemData.qty = sm[i].get('qty');
// so can out from loop
i = sm.length;
}
}
Ext.Ajax.request({
url: BASE_URL + 'product/ext_add_cart',
method: 'POST',
params: {
'id': data.itemData.id,
'price': data.itemData.price,
'name': data.itemData.name,
'rowid': data.itemData.rowid,
'qty': data.itemData.qty
},
success: function() {
strCart.load();
}
});
return(true);
}
});
That's all for the Cart features, there is CheckboxSelectionModel component, this component is to check whether the product is already on the cart, you can see it used on notifyDrop inside the dropTarget you have to add, the expected result is something like this.
To download full source of this application Click Here
PHP CMS Frameworks
March 23, 2014
Read more →
Zend
Simple Form Validator For Zend Framework 2 Forms
In this article, we are going to discuss about How to implement the form validator in the Zend Framework 2 forms. Zend Framework is based on simplicity, object-oriented best practices, corporate friendly licensing, and a rigorously tested agile codebase.
Zend Framework is focused on building more secure, reliable, and modern Web 2.0 applications & web services, and consuming widely available APIs from leading vendors like Google, Amazon, Yahoo!, Flickr, as well as API providers and cataloguers like StrikeIron and Programmable Web.
Here is some extended core helping to auto validate Zend Framework 2 Forms.
Step 1 : Extending Zend Framework 2 Form.
<?php
//File : App_folder/module/Module_name/src/Module_name/Form/ExtendedForm.php
namespace Application\Form;
use Zend\Form\Form;
class ExtendedForm extends Form {
protected $_name;
protected $_rawElements = array();
public function __construct($name = null) {
parent::__construct($name);
}
public function isValid($request = null) {
$this->__addValidator();
if ($request -> isPost()) {
$query = $request -> getQuery();
$query = is_object($query) ? $query->toArray() : $query;
$post = $request -> getPost();
foreach($post as $var=>$value){
$query[$var] = $value;
}
$this -> setData($query);
return parent::isValid();
} else {
return false;
}
}
public function add($elementOrFieldset, array $flags = array()) {
$form = parent::add($elementOrFieldset, $flags);
$this->_rawElements[] = $elementOrFieldset;
return $form;
}
private function __addValidator() {
$this -> setInputFilter(new ExtendedFormValidator($this->_rawElements));
}
}
Step 2 : Creating Zend Framework 2 Form validator
//File : App_folder/module/Module_name/src/Module_name/Form/ExtendedFormValidator.php
namespace Application\Form;
use Zend\InputFilter\InputFilter;
class ExtendedFormValidator extends InputFilter {
public function __construct($elements) {
foreach ($elements as $element) {
if (is_array($element)) {
if (isset($element['type'])) {
unset($element['type']);
}
$this -> add($element);
}
}
}
}
Step 3 : Creating simple Zend Framework 2 Form and extending it with ExtendedForm
//File : App_folder/module/Module_name/src/Module_name/Form/ResendPassword.php
namespace Application\Form;
class ResendPassword extends ExtendedForm
{
public function __construct($name = null)
{
parent::__construct('login');
$this->setAttribute('method', 'post');
$this->add(array(
'required'=>true,
'name' => 'usermail',
'type' => 'Zend\Form\Element\Text',
'options' => array(
'label' => 'Email',
),
'filters'=>array(
array('name'=>'StripTags'),
array('name'=>'StringTrim'),
),
'validators'=>array(
array('name'=>'EmailAddress')
),
));
$this->add(array(
'name' => 'submit',
'type' => 'Zend\Form\Element\Text',
'attributes' => array(
'type' => 'submit',
'value' => 'Submit',
'id' => 'submitbutton',
),
));
}
}
Step 4 : Instantiating the Zend Framework 2 Form.
//File : App_folder/module/Module_name/src/Module_name/Controller/IndexController.php
use Application\Form as Form; //at the top of the file.
public function forgotAction(){
$form = new Form\ResendPassword();
if($form->isValid($this->getRequest())){
//do your magic
}
return new ViewModel(array('form'=>$form));
}
Step 5 : Rendering Zend Framework 2 Form in the View.
//File : App_folder/module/Module_name/View/Module_name/index/index.phtml
$form = $this->form;
$form->prepare();
echo $this->view->form()->openTag($form) . PHP_EOL;
$elements = $form->getElements();
foreach($elements as $element){
echo $this->view->formRow($element) . PHP_EOL;
}
echo $this->view->form()->closeTag($form) . PHP_EOL;
Zend Framework is focused on building more secure, reliable, and modern Web 2.0 applications & web services, and consuming widely available APIs from leading vendors like Google, Amazon, Yahoo!, Flickr, as well as API providers and cataloguers like StrikeIron and Programmable Web.
Here is some extended core helping to auto validate Zend Framework 2 Forms.
Step 1 : Extending Zend Framework 2 Form.
<?php
//File : App_folder/module/Module_name/src/Module_name/Form/ExtendedForm.php
namespace Application\Form;
use Zend\Form\Form;
class ExtendedForm extends Form {
protected $_name;
protected $_rawElements = array();
public function __construct($name = null) {
parent::__construct($name);
}
public function isValid($request = null) {
$this->__addValidator();
if ($request -> isPost()) {
$query = $request -> getQuery();
$query = is_object($query) ? $query->toArray() : $query;
$post = $request -> getPost();
foreach($post as $var=>$value){
$query[$var] = $value;
}
$this -> setData($query);
return parent::isValid();
} else {
return false;
}
}
public function add($elementOrFieldset, array $flags = array()) {
$form = parent::add($elementOrFieldset, $flags);
$this->_rawElements[] = $elementOrFieldset;
return $form;
}
private function __addValidator() {
$this -> setInputFilter(new ExtendedFormValidator($this->_rawElements));
}
}
Step 2 : Creating Zend Framework 2 Form validator
//File : App_folder/module/Module_name/src/Module_name/Form/ExtendedFormValidator.php
namespace Application\Form;
use Zend\InputFilter\InputFilter;
class ExtendedFormValidator extends InputFilter {
public function __construct($elements) {
foreach ($elements as $element) {
if (is_array($element)) {
if (isset($element['type'])) {
unset($element['type']);
}
$this -> add($element);
}
}
}
}
Step 3 : Creating simple Zend Framework 2 Form and extending it with ExtendedForm
//File : App_folder/module/Module_name/src/Module_name/Form/ResendPassword.php
namespace Application\Form;
class ResendPassword extends ExtendedForm
{
public function __construct($name = null)
{
parent::__construct('login');
$this->setAttribute('method', 'post');
$this->add(array(
'required'=>true,
'name' => 'usermail',
'type' => 'Zend\Form\Element\Text',
'options' => array(
'label' => 'Email',
),
'filters'=>array(
array('name'=>'StripTags'),
array('name'=>'StringTrim'),
),
'validators'=>array(
array('name'=>'EmailAddress')
),
));
$this->add(array(
'name' => 'submit',
'type' => 'Zend\Form\Element\Text',
'attributes' => array(
'type' => 'submit',
'value' => 'Submit',
'id' => 'submitbutton',
),
));
}
}
Step 4 : Instantiating the Zend Framework 2 Form.
//File : App_folder/module/Module_name/src/Module_name/Controller/IndexController.php
use Application\Form as Form; //at the top of the file.
public function forgotAction(){
$form = new Form\ResendPassword();
if($form->isValid($this->getRequest())){
//do your magic
}
return new ViewModel(array('form'=>$form));
}
Step 5 : Rendering Zend Framework 2 Form in the View.
//File : App_folder/module/Module_name/View/Module_name/index/index.phtml
$form = $this->form;
$form->prepare();
echo $this->view->form()->openTag($form) . PHP_EOL;
$elements = $form->getElements();
foreach($elements as $element){
echo $this->view->formRow($element) . PHP_EOL;
}
echo $this->view->form()->closeTag($form) . PHP_EOL;
PHP CMS Frameworks
March 16, 2014
Read more →
CodeIgniter
Creating User Managament system Using Codeigniter and Extjs
This article is to showing my little idea about how to manage user permission in ExtJS component. In this post I not showing the full source code, just a little part of the code to get the idea how it works, however the complete source code still available on the download link at the end of this article.
The below example is a simple user management that user can manipulate other user data and users groups, user need to logged in to the system to do some action, and the feature are:
- Add, Update, Delete Users
- Add, Update, Delete Groups
- Administrator cannot be deleted or updated
Which mean it will take different action button in the application screen, depend on the users groups, what is not handled in this example is user restriction, if a group have granted to modify certain user, it can modify whole user although it is the administrator.
The image is the file structure that I have created on this example, there will be a form and two grid panel in this application, a usual login form with label and textfield, a grid contain user data with the toolbar menu and a grid contain group data.
In the database, we need to make a relation between user and groups and here the sql code that I created, for both groups and users table.
-- Table structure for table `groups`
CREATE TABLE IF NOT EXISTS `groups` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`user_add` int(1) NOT NULL,
`user_edit` int(1) NOT NULL,
`user_delete` int(1) NOT NULL,
`group_add` int(1) NOT NULL,
`group_edit` int(1) NOT NULL,
`group_delete` int(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;
-- Table structure for table `users`
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`group_id` int(11) NOT NULL,
`username` varchar(50) NOT NULL,
`password` varchar(100) NOT NULL,
`real_name` varchar(150) NOT NULL,
`email` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
The below example is a simple user management that user can manipulate other user data and users groups, user need to logged in to the system to do some action, and the feature are:
- Add, Update, Delete Users
- Add, Update, Delete Groups
- Administrator cannot be deleted or updated
Which mean it will take different action button in the application screen, depend on the users groups, what is not handled in this example is user restriction, if a group have granted to modify certain user, it can modify whole user although it is the administrator.
The image is the file structure that I have created on this example, there will be a form and two grid panel in this application, a usual login form with label and textfield, a grid contain user data with the toolbar menu and a grid contain group data.
In the database, we need to make a relation between user and groups and here the sql code that I created, for both groups and users table.
-- Table structure for table `groups`
CREATE TABLE IF NOT EXISTS `groups` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`user_add` int(1) NOT NULL,
`user_edit` int(1) NOT NULL,
`user_delete` int(1) NOT NULL,
`group_add` int(1) NOT NULL,
`group_edit` int(1) NOT NULL,
`group_delete` int(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;
-- Table structure for table `users`
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`group_id` int(11) NOT NULL,
`username` varchar(50) NOT NULL,
`password` varchar(100) NOT NULL,
`real_name` varchar(150) NOT NULL,
`email` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
The groups table contains id, group name and all the action that user can do to the application, from the user_add field until group_delete column the value only contains 1 or 0, which mean 1 for user can do this action and zero otherwise, The idea to managing user interface is by disabling the button on the toolbar based on the user group permissions and this are generated from groups table, so we need to give a unique Id for each button.
As well in the controller there are two controller that we need to create, user controller in application/controllers/user.php and group controller in application/controllers/group.php. Inside the user controller create the function for login and fetching users session inside user controller.
public function ext_login()
{
$cond = array(
'username' => $_POST['textusername'],
'password' => $_POST['textpassword']
);
$query = $this->db->get_where('users', $cond);
if ($query->num_rows() != 0)
{
$row = $query->row();
// get group detail
$g_cond = array(
'id' => $row->group_id
);
$g_query = $this->db->get_where('groups', $g_cond);
$g_row = $g_query->row();
// pass the the info to session
$this->session->set_userdata('u_id', $row->id);
$this->session->set_userdata('u_name', $_POST['textusername']);
$this->session->set_userdata('g_id', $g_row->id);
$this->session->set_userdata('g_u_add', $g_row->user_add);
$this->session->set_userdata('g_u_edit', $g_row->user_edit);
$this->session->set_userdata('g_u_delete', $g_row->user_delete);
$this->session->set_userdata('g_g_add', $g_row->group_add);
$this->session->set_userdata('g_g_edit', $g_row->group_edit);
$this->session->set_userdata('g_g_delete', $g_row->group_delete);
echo "{success:true}";
}
else
{
echo "{success:false, error:'User not found!'}";
}
}
public function ext_get_session()
{
$output = "{success:true, sessions: {";
$output .= "u_id: '".$this->session->userdata('u_id')."',";
$output .= "u_name: '".$this->session->userdata('u_name')."',";
$output .= "g_id: '".$this->session->userdata('g_id')."',";
$output .= "g_u_add: '".$this->session->userdata('g_u_add')."',";
$output .= "g_u_edit: '".$this->session->userdata('g_u_edit')."',";
$output .= "g_u_delete: '".$this->session->userdata('g_u_delete')."',";
$output .= "g_g_add: '".$this->session->userdata('g_g_add')."',";
$output .= "g_g_edit: '".$this->session->userdata('g_g_edit')."',";
$output .= "g_g_delete: '".$this->session->userdata('g_g_delete')."'";
$output .= "}}";
echo $output;
}
The ext_get_sessions function above is to get session and pass it to the browser, and in the login function the session value will be defined when user logged in to the system, ext_get_sessions function will be used in the permissions.js, I'm sure you can add the logout function contain the code to unset all the sessions value and here the permissions function look like inside the permissions.js.
function setPermissions() {
Ext.Ajax.request({
url: BASE_URL + 'user/ext_get_session',
method: 'POST',
success: function(o) {
var obj = Ext.util.JSON.decode(o.responseText);
// set enable/disable grid panel
if (obj.sessions.u_id != '') {
Ext.getCmp('fLogin').setDisabled(true);
Ext.getCmp('gUsers').setDisabled(false);
Ext.getCmp('gGroups').setDisabled(false);
Ext.getCmp('userLabel').setText('Welcome "'+obj.sessions.u_name+'"');
} else {
Ext.getCmp('fLogin').setDisabled(false);
Ext.getCmp('gUsers').setDisabled(true);
Ext.getCmp('gGroups').setDisabled(true);
Ext.getCmp('userLabel').setText('Please Login');
}
// set users toolbar button
if (obj.sessions.g_u_add == '1') {
Ext.getCmp('tbUserAdd').setDisabled(false);
} else {
Ext.getCmp('tbUserAdd').setDisabled(true);
}
if (obj.sessions.g_u_edit == '1') {
Ext.getCmp('tbUserEdit').setDisabled(false);
} else {
Ext.getCmp('tbUserEdit').setDisabled(true);
}
if (obj.sessions.g_u_delete == '1') {
Ext.getCmp('tbUserDelete').setDisabled(false);
} else {
Ext.getCmp('tbUserDelete').setDisabled(true);
}
// set groups toolbar button
if (obj.sessions.g_g_add == '1') {
Ext.getCmp('tbGroupAdd').setDisabled(false);
} else {
Ext.getCmp('tbGroupAdd').setDisabled(true);
}
if (obj.sessions.g_g_edit == '1') {
Ext.getCmp('tbGroupEdit').setDisabled(false);
} else {
Ext.getCmp('tbGroupEdit').setDisabled(true);
}
if (obj.sessions.g_g_delete == '1') {
Ext.getCmp('tbGroupDelete').setDisabled(false);
} else {
Ext.getCmp('tbGroupDelete').setDisabled(true);
}
}
});
}
As you can see on the code above, I manipulate the ExtJS component based on "Id", so we need to to add Id properties for the required component, here a part of login form script and the form id I called it 'fLogin' ( assets/js/login.js )
// part of login.js
var loginForm = new Ext.FormPanel({
id: 'fLogin'
});
function fnLogin() {
loginForm.getForm().submit({
success: function() {
setPermissions();
strUsers.load();
},
failure: function(form, o) {
if (typeof(o.response) != 'undefined') {
var json = o.response.responseText;
var r = Ext.util.JSON.decode(json);
Ext.Msg.alert('Login failed', r.error);
}
}
});
}
Now part of the user script in ExtJS ( assets/js/user.js )
// part of user.js
var tbUsers = new Ext.Toolbar({
items: [{
text: 'Add',
id: 'tbUserAdd'
}, '-', {
text: 'Edit',
id: 'tbUserEdit'
}, '-', {
text: 'Delete',
id: 'tbUserDelete'
}, '->', {
text: '',
xtype: 'label',
style: 'color:#0066cc;font-weight:bold;',
id: 'userLabel'
}, '-', {
text: 'Logout'
}]
});
var gridUsers = new Ext.grid.GridPanel({
id: 'gUsers'
});
In the group script (assets/js/group.js)
var tbGroups = new Ext.Toolbar({
items: [{
text: 'Add',
id: 'tbGroupAdd'
}, '-', {
text: 'Edit',
id: 'tbGroupEdit'
}, '-', {
text: 'Delete',
id: 'tbGroupDelete'
}]
});
var gridGroups = new Ext.grid.GridPanel({
id: 'gGroups'
});
For the adding and editing users and group I'm using a pop up window that have form to be submitted inside it, and for delete action I'm just using simple alert confirmation box. Well I think it is too much if I show all the code in this post, just go to the download link if you want to see full source code of this example, and here some of the screen capture.
Click Here to download the source files.
PHP CMS Frameworks
March 13, 2014
Read more →
Joomla
Steps to integrate Google Authorship with Joomla
In this article, we are going to discuss about the step by step procedure to integrate the Google Authorship with Joomla. Google Authorship is used to integrate the articles which are created inside Joomla with Google Plus. This can give more exposure to your social profile because you are listed in Google search results as the author. Integrating the Google Authorship with Joomla will lead to more click through from people who see your photo and trust the result. It will also lead to Google to rank your content.
Step 1 : Install SD Google Authorship
Download and unzip the SD Google Authorship. Then, Extract this file to get the available versions for Joomla 1, 2 and 3. Install the unzipped "SD Google Authorship" package in Joomla and Enable it in Plugin Manager page.
Step 2 : Add your Google Plus link to Contacts
Step 3 : Register your site with Google
Step 1 : Install SD Google Authorship
Download and unzip the SD Google Authorship. Then, Extract this file to get the available versions for Joomla 1, 2 and 3. Install the unzipped "SD Google Authorship" package in Joomla and Enable it in Plugin Manager page.
Step 2 : Add your Google Plus link to Contacts
- The SD Google Authorship plugin using the default Contacts component. So, go to Extensions >> Contacts >> Contact >> and either create a new contact or edit an existing one.
- Set the Linked User field to link to your user account.
- Set the Website field using your own Google+ profile URL.
- Complete the other fields as you need and click Save & Close.
Step 3 : Register your site with Google
- Go to https://plus.google.com/authorship and add your Joomla site's URL to your profile.
- Google says it will take between several days to several weeks before it starts showing your photo and profile information in search results.
PHP CMS Frameworks
March 10, 2014
Read more →
CakePHP
Easy way to use ajax in cakephp controller action
AJAX is about updating parts of a web page, without reloading the whole page. We need ajax many times to create a dynamic web application. In this article, we are going to discuss about easiest way to use the Ajax in Cakephp controller action. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
In cakephp, to manipulate data by ajax we need to call some controller's action with some parameters, by the following ajax call we can easily pass the parameters to that action.
Example of ajax implementation in cakephp
<script>
$(document).ready(function(){
$.ajax({
dataType: "html",
type: "POST",
evalScripts: true,
url: '<?php echo Router::url(array('controller'=>'admin_employees','action'=>'emp_return'));?>',
data: ({dutylocation:dloc,dutytype:dtype}),
success: function (data, textStatus){
$(".UserInfoDiv").html(data);
}
});
});
</script>
<html>
<div class='UserInfoDiv'></div>
</html>
In cakephp, to manipulate data by ajax we need to call some controller's action with some parameters, by the following ajax call we can easily pass the parameters to that action.
Example of ajax implementation in cakephp
<script>
$(document).ready(function(){
$.ajax({
dataType: "html",
type: "POST",
evalScripts: true,
url: '<?php echo Router::url(array('controller'=>'admin_employees','action'=>'emp_return'));?>',
data: ({dutylocation:dloc,dutytype:dtype}),
success: function (data, textStatus){
$(".UserInfoDiv").html(data);
}
});
});
</script>
<html>
<div class='UserInfoDiv'></div>
</html>
PHP CMS Frameworks
March 05, 2014
Read more →
Magento
Steps to Add CMS blocks into pages in Magento
In this article, we are going to discuss about How to add the CMS blocks into the pages in Magento. Magento is a popular E-commerce CMS framework. Magento is a feature-rich, open-source, enterprise-class platform that offers merchants a high degree of flexibility and control over the user experience, catalog, content and functionality of their online store. We can add CMS blocks into Magento pages in 2 ways.
Step 1 : Using the xml layouts
<block type="cms/block" name="block_name" as="block_name" after="-">
<action method="setBlockId"><block_id>the_block_id</block_id></action>
</block>
Step 2 : Using the phtml files
<?php
echo $this->getLayout()->createBlock('cms/block')->setBlockId('the_block_id')->toHtml() ;
?>
Step 1 : Using the xml layouts
<block type="cms/block" name="block_name" as="block_name" after="-">
<action method="setBlockId"><block_id>the_block_id</block_id></action>
</block>
Step 2 : Using the phtml files
<?php
echo $this->getLayout()->createBlock('cms/block')->setBlockId('the_block_id')->toHtml() ;
?>
PHP CMS Frameworks
March 02, 2014
Read more →
No more posts to load.
About this blog
PHPCMSFramework.com
Tutorials for WordPress, Laravel, Drupal, Joomla, Symfony & more — including AI-powered PHP guides. Publishing since 2012.
Trending posts
- Building a RAG System in Laravel from Scratch
- Steps to create a Contact Form in Symfony With SwiftMailer
- Build an AI Code Review Bot with Laravel — Real-World Use Case
- Build a WhatsApp AI Assistant Using Laravel, Twilio and OpenAI
- CIBB - Basic Forum With Codeigniter and Twitter Bootstrap
- Drupal 7 - Create your custom Hello World module
- Laravel and Prism PHP: The Modern Way to Work with AI Models
- Create Front End Component in Joomla - Step by step procedure
- A step by step procedure to develop wordpress plugin
- Migrating a wordpress website to Joomla website
Blog Archive
-
▼
2014
(86)
-
▼
March
(8)
- Steps to display the Twitter Feed in a Drupal Block
- Steps to resolve the broken Captcha in Joomla 2.5 ...
- Drag and Drop Shopping Cart Using CodeIgniter Cart...
- Simple Form Validator For Zend Framework 2 Forms
- Creating User Managament system Using Codeigniter ...
- Steps to integrate Google Authorship with Joomla
- Easy way to use ajax in cakephp controller action
- Steps to Add CMS blocks into pages in Magento
-
▼
March
(8)


