Reputation: 3266
i have used this code form external php script to include the codeigniter controller file.
include_once "codeigniter/index.php/user";
it doesn't work.
'user'
is my controller file.
However i can include by making 'user'
the default controller page
$route['default_controller']="user";
and use as:
include_once "codeigniter/index.php";
but what if i need other controller files?
update:
Also, the controller file could be linked through external php script:
<a href="codeigniter/index.php/user">click here</a>
Upvotes: 2
Views: 1874
Reputation: 6539
CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php
file and set this variable:
$route['default_controller'] = 'User';
Where User
is the name of the controller class you want used. If you now load your main index.php
file without specifying any URI segments you'll see your Hello World message by default.
In your case, you can call any controller by:-
http://localhost/codeigniter/index.php/controller_name/method_name/
This tutorial link will explain better :)
To call CI controller outside you should use cURL.
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'Your_CI_CONTROLLER_URL');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)){
print "Nothing returned from url.<p>";
}
else{
print $buffer;
}
Upvotes: 1