Archive for the ‘php’ Tag

Adding external (Menu) JavaScript, CSS and Images in a project using CodeIgniter

Open config.php file (Under application/config folder) and change the following line

$config['base_url'] = “”;

to

$config['base_url'] = “http://localhost/cimenu”; //here cimenu is the folder where all the files of CodeIgniter is

Now open autoload.php file (Under application/config folder) and change the following line

$autoload['helper'] = array();

to

$autoload['helper'] = array(‘url’, ‘form’);

Now create a folder named menu under cimenu(This is the project name) folder, that is, in your root folder. Now put all the files of the external menu to the menu folder under cimenu.

Lets create a php file and name it mymenu.php under application/controller folder and write the following code:

<?php

class Mymenu extends Controller

{

function Mymenu()

{

parent::Controller();

}

function index()

{

$this->load->view(‘menuview’);

}

}

?>

In application/view folder create a php and name it as menuview.php and write the following code:

<html>

<head>

<title>My Menu</title>

</head>

<body>

<?php $this->load->view(‘menu’); ?>

</body>

</html>

Now create another php file name it as menu.php in application/view folder. This is the file where all the code of your menu is. Here if you need to call any CSS, JavaScript or image you have to use <?=base_url();?> because it is your base url where all the external files is.

It this project there is one CSS and one JavaScript file in menu folder under cimenu. We can include it by the following line respectively.

<link rel=”stylesheet” type=”text/css” href=”<?=base_url();?>menu/sdmenu.css” />

<script type=”text/javascript” src=”<?= base_url();?>menu/sdmenu.js”></script>

The full menu.php code is as follows:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

<title>My Menu</title>

<link rel=”stylesheet” type=”text/css” href=”<?=base_url();?>menu/sdmenu.css” />

<script type=”text/javascript” src=”<?= base_url();?>menu/sdmenu.js”></script>

</script>

<script type=”text/javascript”>

// <![CDATA[

var myMenu;

window.onload = function() {

myMenu = new SDMenu("my_menu");

myMenu.init();

};

// ]]>

</script>

</head>

<body>

<div style=”float: right” id=”my_menu” class=”sdmenu”>

<div>

<span>Admission</span>

<a href=”#” mce_href=”#”>Image Optimizer</a>

<a href=”#” mce_href=”#”>FavIcon Generator</a>

<a href=”#” mce_href=”#”>Email Riddler</a>

<a href=”#” mce_href=”#”>htaccess Password</a>

<a href=”#” mce_href=”#”>Gradient Image</a>

<a href=”#” mce_href=”#”>Button Maker</a>

</div>

<div>

<span>Exam</span>

<a href=”#” mce_href=”#”>Recommend Us</a>

<a href=”#” mce_href=”#”>Link to Us</a>

<a href=”#” mce_href=”#”>Web Resources</a>

</div>

<div class=”collapsed”>

<span>Courses</span>

<a href=”#” mce_href=”#”>JavaScript Kit</a>

<a href=”#” mce_href=”#”>CSS Drive</a>

<a href=”#” mce_href=”#”>CodingForums</a>

<a href=”#” mce_href=”#”>CSS Examples</a>

</div>

<div class=”collapsed”>

<span>Notice</span>

<a href=”#” mce_href=”#”>Current or not</a>

<a href=”#” mce_href=”#”>Current or not</a>

<a href=”#” mce_href=”#”>Current or not</a>

<a href=”#” mce_href=”#”>Current or not</a>

</div>

</div>

</body>

</html>

You can add image by adding the following code in the menu.php file, you must have a folder name images in the root directory, i.e. in the cimenu folder.

<img src=”<?=base_url();?>images/myimage.gif” />

Just PHP will give you nothing… unless you upgrade yourself by Hasin Hayder by Hasin Hayder

This topic was actually posted by Hasin Bhai, I just made a summary of it and want to find out from here what should i learn next.

CSS: (maintain a list of websites where from you can get updates. Dont learn the CSS from book, but goto websites and see what is happening)

JS: you have to have some basic skills on basic javascript, but dont spend time for re inventing the wheels. Go for popular libs like Prototype, jQuery, Moo, Mootools, Scriptaculous, Dojo, Rico

Frameworks: Have to have proper knowledge on MVC framework. Most Popular frameworks for PHP are CodeIgniter, CakePHP, Symfony

Never wait for only MySQL. Learn postgreSQL. PostgreSQL also developed a lot. Now its hardly a factor between them, if you talk abt performance. Beside that I must say postgre is much more mature, feature rich and thats why it is called “open source oracle”. And it is also necessary to learn atleast one of the embedded database like SQLite. Dont ever think that SQLite is less powerull. You can develop amazing apps using simply SQLite, with some “hacks” and “optimizations”.

If you are PHP developer and think you have learned enough already, let me give some suggestions. Please DONT think you have finished learning. Everyday there are new release from PEAR, PECL and many other providers. Please learn useful packages from PEAR. Also learn the following:

1. ezComponents
2. Zend Framework (dont mix framework with the MVC concept.. MVC is just a part of Zend Framework)
3. Popular opensource packages
4. PEAR
5. Templating engines like Smarty, Savant.

also keep yourself uptodate from the following sites

1. www.phparch.com
2. www.phpmag.net
3. www.phpmagazine.net
4. www.ajaxian.com
5. www.mashable.com
6. www.programmableweb.com
7. www.planet-php.org

Naming convention for Variable and other’s in PHP

  • Variable
    • Local Variable (lower case: EX. $stdtname)
    • Global Variable (Starts with a g: EX. gStudentname

Some Important Recognized variables:

i => Counter Variable

n => Count Variable

m => Represents n, if n is used

j => Represents i, if i is used

k => Represents i, if i is used

  • Class (Starting character is Capital: EX. class Maritalstatus)
  • Function (Camal Case: EX. function MyFunction()
  • Parameter/Argument (Starts with p, then camel case)
  • Instantiate (Class/Object starts with m, then camel case)
  • Controls (Starts with meaningful short name, then your chosen name in Camel Case: Ex. txtPersonName)
  • Form Elements (Starts with frm, then your chosen name in camel case: EX. frmMyForm)

implement

Database Name: Represent/Separate it by underscore to have a Meaning full name. Name should be all lower case (By Default MySQL treats database as lower case, what ever name you give it)

Table Name: Lower case, Separated by underscore (If needed)

Field Name: Should be meaningful and Camel Case.