Controllers/home.php code is:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$this->load->view('index');
}
}
?>
Config/routes.php code is:
$route['default_controller'] = 'home';
This code is for view only index page. I create folder in views named pitanja, and several pages in that folder. Problem is when i click on site on that pages, i get error 404 page. Where i miss?
$this->load->view('pitanja/index');// relative to APPPATH.'views' directory
Just store pitanja folder with application|system|user_guid and it will display pages. Solved!
Related
Here is my pages.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
public function index()
{
$this->load->view('home');
}
public function event()
{
$this->load->view('event');
}
public function envi()
{
$this->load->view('envi');
}
public function tour()
{
$this->load->view('tour');
}
Can you guys help me out when click on button localhost/social/pages/envi this is opens.. but i need that file should be access and url should localhost/envi how to do that can u guys help me
There are number of ways for doing this
Like you can set apache rule in .htaccess file OR
Define your routing in this file
application/config/routes.php
Put this line of code in routes.php
$route ['envi'] = "social/pages";
URL will go like this
http://localhost/envi
Hi ShanmukSrinivas Gandepalli,
There a file routes.php in the config folder, open it add define your action here
Like below, here home is controller name and aboutus is method name. Now you can call this by aboutus no need to add contoller in the url.
$route['aboutus'] = 'page/aboutus';
Hope this will help you!
We did a fresh install of codeigniter 3.0.6 in our hosting and everytime we are changing
$route['default_controller'] = 'welcome';
to
$route['default_controller'] = 'home';
we are receiving a 404 error message.
Does anyone know how to fix this?
CodeIgniter 3.0+ has changed there naming conversations.
In your image your controller name define as home.php. Check first letter. Its should be caps.
change home.php to Home.php
Inside Home.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
}
I'm currently learning Codeigniter. As you know, there is a default file called welcome.php in the controller when you first install the package.
I tried to modify that page to index.php, and here is the code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Index extends CI_Controller {
public function index()
{
$this->load->view('welcome_message');
}
}
I also changed the route.php in the config file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'Index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Then I access the page by entering this path: http://localhost/CI/index.php, but it says there are two errors:
Message: Undefined property: Index::$load. Filename: controllers/Index.php
Message: Call to a member function view() on null. Filename:controllers/Index.php
Did I forget to change something else in order to make it work?
I downloaded CI3.0.2 and tried your code in my computer. I encountered the same problem, and with a few time debug I found what caused this problem.
Your class is Index and your function is index two, in php class when you don't define constructor __construct it will try to find if there's a method that have same name with class nameIndex, so in this situation index function is the constructor of class Index. if this confuse you see this document : constructor php official document
Solution:
class Index extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('welcome_message');
}
}
I am new to coding and have fallen in love with codeigniter and recently moved from a wamp server to a LAMP server. I've extracted codeigniter into /var/www/ and set the root directory of the host in apache. I can see the codeigniter welcome page, however if I change the default controller in config.php to my controller and load this controller:
class Site extends CI_Controller {
public function index() {
$this->load->view('home_view');
}
}
I get this text in my browser:
$this -> load -> view ('home_view'); }}
The only line of my index function as well as a codeigniter generated 404 error below it.
base_url() and default controller are set, codeigniter welcome page works fine, but my page does not.
Does anyone have an idea as to why? Your help is very much appreciated.
Make sure your controller is inside application/controllers and the name is site.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('home_view');
}
}
I also done a single webpage into the codeigniter.
But performing "href" it doesn't works.
Give a solution for how to include whole site into the codeigniter.
I think may be i need to create controller(into the directory) files for each and every view(into the directory) files.
Note : My whole templates are in the "view/pages" folder.
i already created "pages.php" in controller folder.
After changing route.php it only works on index.php. not for all other pages when perform links from index page.
My pages.php code is below
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pages extends CI_Controller
{
function view()
{
$this->load->view('templates/header.php');
$this->load->view('pages/index');
//$this->load->view('pages/login');
$this->load->view('templates/footer.php');
}
}
?>
I dont understand you. Do you mean something like this?
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pages extends CI_Controller
{
function index()
{
$this->load->view('templates/header.php');
$this->load->view('pages/index');
//$this->load->view('pages/login');
$this->load->view('templates/footer.php');
}
function aboutUs()
{
$this->load->view('templates/header.php');
$this->load->view('pages/aboutUs');
$this->load->view('templates/footer.php');
}
}
?>
In this way you reach your index page through www.yourserver.ext/pages/ (or www.yourserver.ext/pages/index) and, for example, your about us page through www.yourserver.ext/pages/aboutUs
Also you can set a param and load the page depending on it