Create virtual host on WAMP 3

Project Links do not work on Wamp Server!!!

In WampServer it is now recommended to create a Virtual Host for each of your projects, even if you hold them in a \wamp\www\subfolder structure. The WampServer home page ( \wamp\www\index.php ) now expects you to have created a Virtual Host for all your projects and will therefore work properly only if you do so.

How to create a Virtual Host in WampServer

There are 3 steps to create your first Virtual Host in Apache, and only 2 if you already have one defined.
Continue reading “Create virtual host on WAMP 3” »

Codeigniter 3 – Fast setup

Download and extract codeigniter. In main folder create another folder named assets. There will be additional files for css, js and more.

Setup configuration files. Go to application/config:
– in autoload.php

$autoload['libraries'] = array('database','session');
$autoload['helper'] = array('url','form');

– in config.php

$config['base_url'] = 'http://www.example.com/';
$config['index_page'] = '';
$config['encryption_key'] = 'someEncryptionKey';
$config['sess_save_path'] = sys_get_temp_dir(); //Fix problems with session

– in database.php

'username' => 'root',
'password' => 'rootPassword',
'database' => 'DatabaseName',

– in routes.php

$route['default_controller'] = 'Main_controller';

Step 2 Create Main_controller file in application/controllers
Easiest way is to copy and rename Welcome.php

Step 3 Create .htaccess file in main folder. This is a must for routing!

RewriteEngine On

RewriteCond %{HTTP_HOST} ^my-domain.com [NC]
RewriteRule ^(.*)$ http://www.my-domain.com/$1 [L,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ http://www.my-domain.com/$2 [R=301,L]
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Multilanguage CodeIgniter 3.0

In this tutorial we will implement multilanguage to CodeIgniter.

Site Default Language
Open the application/config/config.php file and specify the site’s default language.

$config['language']  = 'bulgarian';  //Language you want to be default

Language Files

The language files must be named with _lang suffix. For example, if you want to create a file containing site’s message translation then the file name might be message_lang.php.

Insert those files into the application/language/ directory with separate sub-directories for each language (for example, english, bulgarian, etc.).
Continue reading “Multilanguage CodeIgniter 3.0” »

Open window with information (AJAX WAY)

In this example we will execute AJAX that will return data which will be visualised in new window (tab).

$(document).on("click", ".sysnav", function(){ //On clicked button
	id=$(this).attr('id');                 //Command that will be executed in script.php
		$.ajax({
			  url:'script.php',
			  type:'POST',
			  data:{ 
				command:id 
			  }  
		}).done(function(data){
			var target = window.open("/admin.php");   //Open new window
			target.NavigationPopup = data;	          //Data to be loaded in new window
		});		
});

Div with class “content” in new window will be filled with data from AJAX.
File “admin.php”(new window) must include this code.

var NavigationPopup;            //Data from ajax

$(document).ready(function(){
	if(NavigationPopup){ 	$('.content').html(NavigationPopup);	} //Fill the "content" div
}

Load jQuery if not loaded (Asynchronous Way)

If you load scripts through ajax and they won’t execute.



After that place your code that you want to run.

Pagination example

PHP and HTML

  • «
  • $last){$top=$last;} if($x<=0){$bottom+=1;$top+=1;} } for($i=$bottom;$i<=$top;$i++){ ?>
  • ">
  • »

jQuery

$(document).on("click",".pbutton",function() {
		var selected = this.text; //Selected page
		if(selected=="«"){selected = 1;} //first rows
		if(selected=="»"){selected = $(".last_page").attr("id");} //last rows
		
		$.ajax({
		  url:'admin.php',
		  type:'POST',
		  data:{ 
			command:"show_regular_quotation", //name of var: value of var  
			selected:selected
		  }  
		 }).done(function(data){
			$(".content").html(data);
		});		
	});

The code is perfectly compatible with bootstrap.