Sunday, May 20, 2012

Make PHP to work in HTML files by some changes on .htacess

Generally most web servers across the internet are configured to treat as PHP files only files that end with .php. In case you need to have your HTML files parsed as PHP (e.g .html) or even if you want to take it further and make your PHP files look like ASP, you can do the following:

For web servers using PHP as apache module:

AddType application/x-httpd-php .html .htm

For web servers running PHP as CGI:

AddHandler application/x-httpd-php .html .htm

In case you wish to do the ASP mimick:

For PHP as module:

AddType application/x-httpd-php .asp

OR

For PHP as CGI:


AddHandler application/x-httpd-php .asp

How to install and configure Apache,PHP,MySql and phpMyadmin on ubuntu

Step 1: Installing apache

Type the below code in terminal and hit enter.

sudo apt-get install apache2
 
Type your ubuntu password and press enter.


After the successful installation  , open your favorite browser and type

http://localhost/
in the address bar and press enter. If you will see ‘It works!’ , then your apache works fine.

 Step 2:
Installing PHP

Open Terminal. And type the below code in terminal and hit enter.

sudo apt-get install php5 libapache2-mod-php5

Type your ubuntu password if needed.

Type y and hit enter to confirm PHP installation.

After the successful installation restart Apache using the below code

sudo /etc/init.d/apache2 restart

Test PHP installation

To test PHP is installed, Type

sudo gedit /var/www/phpinfo.php

in the terminal and type your ubuntu password if needed. It will open the phpinfo.php file in gedit.Type below code in the phpinfo.php file, save and exit it .



Now open your favorite browser and type http://localhost/phpinfo.php in the address bar and press enter. If you will see the below page , then your php works fine.

Step 3:
Installing MySql

Open Terminal. And type the below code in terminal and hit enter.

sudo apt-get install mysql-server

Type your ubuntu password if needed.

Type y and hit enter to confirm MySql installation.
During the installation you will be prompted for a password.Choose something secure and type the password and hit enter .


 Repeat the password and press enter.
 
 
 
Step 4:
Installing phpMyadmin

phpMyAdmin is a free software tool written in PHP intended to handle the administration of MySQL over the World Wide Web.

Open Terminall. And type the below code in terminal and hit enter.

sudo apt-get install phpmyadmin

Type your ubuntu password if needed.

Type y and hit enter to confirm phpMyadmin installation.

During the installation you will be prompted for a webserver configuration.
Select

apache2

(already selected)
press enter. 


Now you will be promped for phpmyadmin configuration

Select

No

and press enter.


Type below command in terminal

sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d

restart your apache server using

sudo /etc/init.d/apache2 restart

Open your browser and type

http://localhost/phpmyadmin/

in the address bar and press enter.

Type your mysql root  username and password to login.







You’re now ready to start building your local website. just put all of your files into
/var/www




Monday, February 6, 2012

Remove plugin and controller name from URL

In cakephp if you want to remove plugin and as well as controller name from URL , just add below line on your's routes.php file.


Router::connect(
'/plugin-name/*',
array(
'plugin' => 'plugin-name',
'controller' => 'controller-name',
'action' => 'view'
)
);

Tuesday, October 4, 2011

Rendering a specific view in cakePHP

In your controller you may want to render a different view than what would conventionally be done.

You can do this by calling render() directly. Once you have called render() CakePHP will not try to re-render the view:


class PagesController extends AppController {

function your_action() {
$this->render('custom_file');
}
}

This would render app/View/Pages/custom_file.ctp instead of app/View/Pages/your_action.ctp

Friday, September 2, 2011

Remove controller name from url

In cakephp if you want to remove controller name from URL , just add below line on your's routes.php file.

Router::connect('/:action', array('controller' => 'pages'));


its come something like that locahost/stiename/action .

We do this generally to show our static pages on site without controller name in URL , page which are likes about us ,contact us ,help and so on.

Thursday, June 23, 2011

Make PHP to work in HTML files with .htacess

Generally most of web servers across the internet are configured to treat as PHP files only files that end with .php. In case you need to have your HTML files parsed as PHP (e.g .html) or even if you want to take it further and make your PHP files look like ASP, you can do the following:

For web servers using PHP as apache module:

AddType application/x-httpd-php .html .htm

For web servers running PHP as CGI:

AddHandler application/x-httpd-php .html .htm

In case you wish to do the ASP mimick:

For PHP as module:

AddType application/x-httpd-php .asp

OR

For PHP as CGI:

AddHandler application/x-httpd-php .asp

Tuesday, November 30, 2010

CakePHP vs CodeIgniter

It’s an good debate topic. But While i worked on different projects with these frameworks and I’ve made a list difference between them –

Auth, ACL Component/Library-
CakePHP has very strong Auth component with Core.
In CodeIgniter – you have to create or find a suitable plugin.

Code Generation
CakePHP’s Bake console can create any of CakePHP’s basic ingredients: models, views and controllers, can create a fully functional application in just a few minutes.

Very badly, Codeigniter doesn’t has code generation from console, you’ve to find out a plugin.

ORM
CakePHP comes with ORM(Object Relational Mapping is a programming technique for converting data between incompatible type systems in databases and object-oriented programming languages) while in CodeIgniter, does not supports.

Scaffolding
CodeIgniter’s Scaffolding feature provides a fast and very convenient way to add, edit, or delete information in your database during development which is deprecated from version 1.6.0.
CakePHP scaffolding is a technique that allows a developer to define and create a basic application that can create, retrieve, update and delete objects. Scaffolding in CakePHP also allows developers to define how objects are related to each other, and to create and break those links.

Ajax
CakePHP comes with Ajax helper which can be used in various ways. i didn’t see this with CodeIgniter core.

PHP Version
Both runs on PHP4 and PHP5 but both doesn’t take any facility of PHP5 while runs on PHP5 Machine. CakePHP declared, their upcoming version 2.0 will runs only on PHP 5.2 which definitely take advantage of PHP5′s OOP and ohter killer features.

Simplicity
I believe CodeIgniter is simple and working with this, it’s so easy while in CakePHP coding process is quicker for expert but its hard to find out what’s going on For Newbie.

MVC
Both of them are MVC supported framework but in Codeigniter you can build your project without Model which may lead messy and unsecured code sometimes(if anybody place direct query without any filtering). Codeigniter Model supports Method Chaining(PHP5 only) feature that’s fantastic. Most important is Model association, which absent in Codeigniter! In CakePHP, query are very simple to get value from a table by any field with related data.

Console
Cakephp came with console features. You can generate code or upgrade db schema from your console. If you are working with a team remotely and you don’t allow other user to handle your db directly – you can use this feature.

CodeIgniter doesn’t has this feature.

Validation
In Codeigniter, validation is handled by a validation class. The validation class can also help automate some of the process of setting error messages for specific fields.
In CakePHP, validation rules are defined in Model, can be validate data before save or at saving.which is little bit diffcult the codeigniter.

View/Layout
CakePHP handles this fairly well by using a default layout, easy to implement header , footer, sidebar while CodeIgniter takes a very straightforward approach – something like buiding a application from scratch. CodeIgniter allows caching mechanism for your view which is pretty good.

File Uploading
I love CodeIgniter’s file uploading class by which it’s very easy to handle uploading files. CakePHP doesn’t has this.

Other Classes
Codeigniter has many classes such as ftp, compression, cart etc etc classes. You may need certain classes for your project which already in CodeIgniter and not with CakePHP but you may find out component most of the time.

Web Services
Both has web services in built in. CakePHP has REST while CodeIgniter has XML-RPC but both doesn’t has SOAP, you need to find out component/plugin.

Auto Calling Functions/Other Functions
In CakePHP, there are few functions which are automatically called every time you refresh/hit a page and executed if you defined them such as beforeSave, afterSave, beforeRender etc – I just love these. I found a function called requestAction in cakephp that calls a controller’s action from any location and returns data from the action, sometimes its very useful.

Helpers
I found CakePHP helpers(such as form helper, it highlight input field for validation error automatically) are powerful than CodeIgniter.

Learning Curve
The learning curve of CakePHP is slightly higher than CodeIgniter. As CakePHP is a shade of ruby on rails, so its easy to get rails or cakephp developer to get them accordingly.

Support
CakePHP has solid support, you will get your answer very shortly while in CodeIgniter, i am still waiting for a answer in CodeIgniter forum, strange!

Documentation
Both are well-documented so far.

CodeIgniter comes with many classes, less of them are frequently used but missed important classes such as auth, straight forward but no automagic feature, MVC but not strict. I missed these features while i was working on a project using CodeIgniter. You may or may not face few problems while learning CakePHP but once you learnt,