Showing posts with label CodeIgniter Tutorials. Show all posts
Showing posts with label CodeIgniter Tutorials. Show all posts

Tuesday, August 21, 2007

CodeIgniter Tutorial #2

my friends ask me, how he could add a css file to the view.
such an easy question for you guys but not for me and my friend
the codeigniter file structure didnt mention where to put your css, image, or javascript file.
hei, dont get me wrong... i just a newbie

then i remember, i've codeigniter application (BambooInvoice by Derek Allard)
this is how BambooInvoice file structure like

+ codeigniter_system
+ img
+ css
+ js

let demonstrate
Here my css file that i store in css/style.css

css/style.css

* {
margin:0;
padding:0;
}

#message {
margin:10px;
padding:10px;
border:1px solid #e1e1e1;
}

.info {
margin-top:15px;
color:#fff;
background: #237295;
padding:4px;
}


and here my controller

codeigniter/system/application/controller/blog.php (controller)

<?php

class Blog extends Controller {

function index() {
$data['title'] = "Yet another blog tutorial";
$data['blogs'] = array();
$this->load->helper('url');
$this->load->view('blog/index', $data);
}
}
?>


and here is my view

codeigniter/system/application/view/blog/index.php (view)


<html>
<head>
<title><?= $title ?></title>
<link rel='stylesheet' type='text/css' media='all'
href='<?php echo base_url()."css/style.css"?>' />
</head>
<body>
<div id="message">
<h1>Welcome to CSS layout!</h1>
This style from style.css
<div class="info">Page rendered in {elapsed_time}
seconds</div>
</div>
</body>
</html>


Note that before you can use base_url function, you have to add url helper by add $this->load->helper('url') to your controller

Friday, August 17, 2007

CodeIgniter Tutorial #1 Installation

I think CodeIgniter installation is straightforward, just follow the instructions from the CodeIgniter user guide
The instructions say

CodeIgniter is installed in four steps:

  1. Unzip the package.
  2. Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.
  3. Open the application/config/config.php file with a text editor and set your base URL.
  4. If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings.

but then again i just wanna share my installation. CodeIgniter, here we come...

Windows CodeIgniter installation

Requirement :
For the servers i use XAMPP (say my thanks for those guy behind XAMPP for bundling what i need),
ok then after my XAMPP installation (just a few click ok..ok..ok and you will get there) and get codeigniter then
  • Unzip the package in your root webroot (in XAMPP .../Program Files/xampp/htdocs/)
  • Rename CodeIgniterXXXX to codeigniter (optional).
  • Start your server (in XAMPP Start->All Programs->apachefriends->xampp->CONTROL XAMPP SERVER PANEL or click XAMPP Control Panel icon in your desktop and start apache and mysql)
  • Open you browser and type http://localhost/codeigniter/

you will see this


and you'r done. Check the user guide for informations, the user guide is awesome.


Linux CodeIgniter installation ( Ubuntu Linux, Feisty Fawn )


Note that in standard Ubuntu installation you wont get apache server, mysql server, and php.
so install those things...

hehehe, well nothing to explain in this section. just follow the steps from the user guide.

i put my CodeIgniter package in my webroot, unzip, and everything goes well except for the mod_rewrite setting. I'll show
you later about my mod_rewrite setting (because of i don't know how to that)

if i made a mistake, tell me about it, i will learn from my mistake, and maybe another person can learn from my mistakes