Reputation: 35
I want to use routing in CodeIgniter i was not able to get i want to pass test controller here's the code I want the url like this localhost/code/test ibut i am getting object not found
routes.php
$route['test'] = "test/blog";
test.php controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->view('welcome_message');
}
public function blog()
{
echo "hi";
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
Upvotes: 2
Views: 1771
Reputation: 2265
if you have not set default controller in route then first of all set it after that set specific routing like this
$route['default_controller'] = "Test";
$route['404_override'] = '';
$route['test'] = 'test/blog';
$route['test/(:any)'] = 'test/blog/$1';
Upvotes: 1
Reputation: 127
First Of all make Default controller to your file. From Route.php
Upvotes: 0
Reputation: 21437
What you want to do is you need to prepare a view page within views
folder like blog.php
and what you need to do is you need to pass data within it and have to call view part within your controller like as
test.php
public function blog()
{
$data['my_post'] = "Hello Its my first blog"; //some sort of operations or else likewise
$this->load->view('blog',$data);
}
within blog.php
<h1><?php echo $my_post;?></h1>
Upvotes: 2