Reputation: 5078
I am learning codeigniter but has gone to some trouble. I created a folder in my htdocs and named it as ci_beginning then I created a controller called hello2 in the controller folder and you_view2 in the view folder. Code for my controller:
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Hello2 extends CI_Controller{
// declare variables or class properties
var $name;
$var $color:
function __contruct(){
parent::__construct();
// give default value
$this->name = "Hello";
$this->color = "red";
}
function you(){
$data['name']=$this->name;
$data['color']=$this->color;
// define variable sent to views
$this->load->view('you_view2', $data);
}
}
code for my view:
<html>
<head>
<meta charset="UTF-8">
<title>Beginning Codeigniter</title>
</head>
<body>
<h1 style="color:<?php echo $color ?>">Hello <?php echo $name; ?></h1>
</body>
</html>
I try to access it by using this in my browser:
http://localhost/ci_beginning/index.php/hello2/you
It's giving me a 404 page not found error. Please tell me what I am doing wrong. If you can show me how to make this easier I would really appreciate it. Thank you.
Upvotes: 0
Views: 167
Reputation: 40639
If you are using Codeigniter 3 then make sure that your file name should start with capital letter and make sure the file name is same as your controller name and in this case it must be Hello2.php
in your controllers
folder.
Also there is error in line,
$var $color:
It should be
var $color;
Upvotes: 3