CPHosting hosting review (cphosting.com.au)

February 20th, 2012 — 2:46am

Lately I have been trying out some Australian based shared hosting accounts for some of my smaller websites that dont need a dedicated server. One such company I have recently tried is Cphosting. I wanted to know if they had servers that were based in Australia and whether they were a reseller for another hosting company. I tried out the live chat and after waiting about 10 seconds was greeted by a friendly member of the support staff. They spent a good half an hour with me patiently answering various questions I had, needless to say I was quite impressed! So I joined up a few minutes later and have been pleasantly surprised by the performance of the shared hosting. To date I have experienced no outages, the only time I needed to contact support was when there was a problem with Cpanel, I again contacted live support and the problem was fixed within 10 minutes. At just $3.95 + GST per month the basic "Cloud Hosting" package is a pretty good deal I think. If you are interested in checking out the host you can sign up by following this link CPhosting.com.au

Comment » | Hosting

Zend Framework Simple Template System

January 31st, 2012 — 11:20pm

For todays post I thought I would share with you a simple way in which you can use ZF with multiple frontend templates. Because of the way ZF implements a MVC setup creating templates for a ZF based website is actually quite easy.

To do this we need to do the following:

1 - Create a new directory within your project 'application' directory called 'Templates'
2 - Create a new directory within the 'Templates' directory called 'Template2'

The trick is basically in getting your Controllers to not look for the default views directory but instead looking for the new Templates directory.

So for example instead of our Controller looking for:

application->views->scripts->index->index.phtml

We now want our Controller to use the Template found at:

application->Templates->Template2->scripts->index->index.phtml

To make the controller look somewhere other than the default location we need to add the following code to our controller, e.g. IndexController.php:

 
    private $active_template = "2";
 
    public function preDispatch() {
        ## Setup Template 2
        if ($this->active_template == "2") {
            $this->_helper->layout()->setLayout("layout_template2");
            $this->view->setScriptPath(APPLICATION_PATH . '/Templates/Template2/scripts/');
            $this->view->setHelperPath(APPLICATION_PATH . '/Templates/Template2/helpers/');
        }
	## Template 3 (duplicate the above code to create as many templates as you want)
    }
 
    public function postDispatch() {
        ## Set Zend_View
        if ($this->active_template != "") {
            $this->view = new Zend_View();
        }
    }
 

Notice in the code above that in preDispatch we define a new layout, in the example case layout_template2. It is important to note that this needs to be placed in the application->layout->scripts directory NOT in the Templates directory. The easiest way I have found is just copy your original layout.php file and rename it to layout_template2.php.

Also from the code above you notice that there is a reference to helper files. As helpers are often styled I usually include them to be part of the templating system. So you can now create helpers as usual specific for the template you are working on and just place them in your Templates directory, i.e.: application->Templates->Template2->helpers->myhelper.php

Now you can create limitless templates which include a new layout, helpers and views.

Comment » | CSS, PHP, Programming, Zend

Simple Zend Twitter Update / Post Tutorial

June 1st, 2011 — 12:28pm

There are some good tutorials around that show you how to use OAuth for client twitter app authenticating. However I have a number of sites that simply tweet certain actions when they occur so don't need the user authentication / callback side of things. Luckily with Zend there is a very easy way to do this and can be done within a controller method or written into a model.

So lets for example make a simple twitter test in a controller

 
 
public function twittertestAction(){
require_once('Zend/Service/Twitter.php');
require_once('Zend/Oauth/Token/Access.php');
 
$AuthConfig = array(
	'callbackUrl' => 'http://www.mysite.com/index/twitternull',
        'siteUrl' => 'http://twitter.com/oauth',
	'consumerKey' => 'sdg3wqt5235dsqwetqwetq',
        'consumerSecret' => 'OUIHihih90fliasf9j2p09af9ufljasp9fa9u3hjIG'
);
 
$mytoken = "986798698-IGIU8kjgiyt9KU8kuoukjgkjguiuiugkIUkughuk";
$mysecret = "HIkljkug7897hkgjkHjhgYFDtyde675efgdgfjJYh";
 
$token = new Zend_Oauth_Token_Access();
$token->setToken($mytoken)
      ->setTokenSecret($mysecret);
 
$message = "This update sent from Zend";
 
$twitter = new Zend_Service_Twitter();
$twitter->setLocalHttpClient(
         $token->getHttpClient($AuthConfig)
);
 
$response = $twitter->status->update($message);
 
print_r($response);
}
 

Thats it!

The callback URL does not have to be valid (I don't think, as it is not actually being used).

Obviously you would probably want to get the consumer keys, token, and secret from a database. Also you could place the above code in a model for application wide access.

1 comment » | Zend

Zend_Auth Simple Cookies Login Authentication System Tutorial / How-To

May 13th, 2011 — 4:46am

This tutorial will explain how to implement a basic Session / Cookie Login system with the Zend Framework.

In a nutshell, we are simply doubling a traditional login system for Zend. One system authenticates from form input (from a login form). The other system authenticates from client Cookie data. The authentication methods for both systems are more or less the same, just adjusted for the input type.

First we need to create a user table which we will call 'publicusers' and a login cookies table which will be called 'login_cookies'.

We have now got one active user in 'publicusers' with email 'test123@test.com' and password 'test'.

Create Databases

publicusers.db

CREATE TABLE IF NOT EXISTS `publicusers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(120) NOT NULL,
`password` varchar(50) NOT NULL,
`salt` varchar(50) NOT NULL,
`role` varchar(50) NOT NULL,
`date_created` datetime NOT NULL,
`name` varchar(100) NOT NULL,
`email_confirmed` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ;

--
-- Dumping data for table `publicusers`
--

INSERT INTO `publicusers` (`id`, `email`, `password`, `salt`, `role`, `date_created`, `name`, `email_confirmed`) VALUES
(101, 'test123@test.com', '0731585d325ecd2b74c25112fccd9bbf54dbd9cd', '0IHOJYA%WhXf7Ykd%$0nwjQT;1oW?hV@2}o\\X101y9v1rcuvfW', '', '2011-04-28 03:41:45', '', 1);

login_cookies.db

CREATE TABLE IF NOT EXISTS `login_cookies` (
`id` int(11) NOT NULL,
`ucode` varchar(50) NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

UsersController.php

Next we need to create a controller called 'UsersController'. This will be used for all regular user authentication purposes.

Using the ZF console tool:

zf create controller Users
 

Next we need to add the following code to this newly create Controller:

 Continue reading »

2 comments » | Zend

Zend Disable Layout and View Rendering in Controller

April 27th, 2011 — 3:55am

These lines are useful for example if you want to pass back a single piece of data to an Ajax request and don't want the layout html code returned.

From within a controller.

Disable Layout:

 
$this->_helper->layout()->disableLayout();
 

Disable View Rendering:

 
$this->_helper->viewRenderer->setNoRender(true);
 

Comment » | Zend

Zend lastInsertId not working – Solved

March 14th, 2011 — 11:56pm

If you are trying to get last insert id with the following, it will not work

 
$this->insert($data);
$id = $this->lastInsertId();
 

To get the last insert id you need to use the adapter. Like so:

 
$this->insert($data);
$id = $this->getAdapter()->lastInsertId();
 

Dont ask me why... If anyone knows why you have to use the getAdapter please let me know.

1 comment » | Zend

Amazon Product Advertising API Down? Up again.

February 28th, 2011 — 2:43am

Suddenly all of my Amazon sites are not working??!?!?
Category search is working but no products are being received. This is across multiple servers and IPs.
Is anyone else seeing this?

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Unavailable

Update: The Product Advertising API is up again. So that was an outage of just a few minutes...

Comment » | Amazon

Problem With Space at Bottom of Page With Skype Button Solution

February 21st, 2011 — 2:43am

To get rid of the space that is strangely added to the bottom of your html when you add a skype status button to your page is really easy.

Simply add this to your css:

 
#skypedetectionswf {
    display: none;
}
 

2 comments » | PHP

How to Copy a Zend Framework Project without ZF Console Problems

February 21st, 2011 — 2:24am

You may have noticed if you have ever tried to copy a ZF project from one website to another that it can cause some problems with the zf console tool.

I had a project located at:

/var/www/mywebsite.com/project01/

That I wanted to copy to the following location in order to start developing a new website

/var/www/newwebsite.com/project01/

To do this correctly so that the zf console tool will still work simply follow these steps:

Assuming you are working from /var/www

 
mkdir /var/www/newwebsite.com
cd /var/www/newwebsite
zf create project project01
cp -R /var/www/mywebsite.com/* /var/www/newwebsite.com/
 

WARNING - You need to do the above in the exact order as described above. If you want to use the zf command line tool make sure it is working properly before starting to edit any of the newly copied code.

DO NOT do what I did which was to copy a project directly, then spend four hours on the index view design and index controller then when the zf console tool was not working do 'zf create project01'!! This completely wiped the following files back to original state:

/public/index.php
/public/.htaccess
/application/views/scripts/index.phtml
/application/controllers/IndexController.php

And I didnt have a backup

Hope this saves someone a headache.

1 comment » | Zend

3 Free Wordpress Blogs

February 19th, 2011 — 7:12am

Came across 3 great free templates at the catswhocode.com blog.

Check them out at: http://www.catswhocode.com/blog/3-quality-free-wordpress-themes-ive-created-for-you

Comment » | Wordpress

Back to top