Codeigniter index.php page - codeigniter

I'd like to set as default page some script from views directory, for example \application\views\index.php and delete index.php file from the root of application. IS it possible? (I tried to change value of config['index_page'] to what i would like, but it gives me error that page not found).
Or maybe codeigniter has so strict project structure that i can't do such changes?

You can't delete index.php file from root directory, instead of that you can remove index.php from the url.
You have to define default controller first, then do follow steps
Have the.htaccess file in the application root directory, along with the index.php file. (Check if the htaccess extension is correct , Bz htaccess.txt did not work for me.)
And Add the following rules to .htaccess file,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Then find the following line in your application/config/config.php file
$config['index_page'] = 'index.php';
Set the variable empty as below.
$config['index_page'] = '';
That's it, it worked for me.
If it doesn't work further try to replace following variable with these parameters ('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO') one by one
$config['uri_protocol'] = 'AUTO';

$config['index_page'] = '';
will do the trick
from now if you access your site like:
http://mypage.com
the default controller would be called
you can change it in routes.php file in your application/config folder
like:
$route['default_controller'] = "views/index";
Btw. your views.php controller in (application/controllers) should look like somehting like that:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Views extends CI_Controller {
public function index()
{
$data = "Text from controller's index method";
$this->load->view('myview', $data);
}
}
And your myview.php in (application/views):
<?php echo $data; ?>

Related

how to run symlink in laravel project inside add-on-domain?

I have an add-on-domain xyz.in inside public_html as 'public_html/xyz.in' and uploaded a laravel project inside xyz.in. However when I am uploading file using storage link the file is not getting saved inside public folder but the image is getting saved in storage folder. I am saving image in the following path
storage/app/public/images/
This is my htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
This is my web.php file inside routes.
Route::get('/clear-cache', function() {
$run = Artisan::call('config:clear');
$run = Artisan::call('cache:clear');
$run = Artisan::call('config:cache');
return 'FINISHED';
});
Artisan::call('storage:link');
Route::get('/', 'frontController#index')->name('homepage');
you can use the code I always use with symlink.
<?php
$target = '/home/public_html/xyz/storage/app/public';
$link = '/home/public_html/xyz/storage';
symlink($target, $link);
echo 'Symlink done!';
You can create a symlink.php file inside public_html/xyz/public and then go to the link.
Example:
http://www.xyx.com/symlink.php
** Don't forget to delete this file after you finish from linking the storage folder.

URL Segment in Codeigniter

In my codeigniter project, i am working around the url parameter. Its almost working but there is some problem in the view page which is loading.
I have set all the configuration as per my knowledge. But I doubt there must be some issue in the .htaccess or routes.php file.
.htaccess file --
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
routes.php --
$route['default_controller'] = 'home';
$route['home'] = 'home/index';
$route['faq'] = 'home/faq';
$route['privacy-policy'] = 'home/policy';
$route['doupnow-videos'] = 'home/videos';
$route['doupnow-audios'] = 'home/audios';
$route['morevideo/(:any)'] = 'home/morevideo/$1';
$route['moreaudio'] = 'home/moreaudio';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Controller Page --
public function morevideo($cat)
{
$result['list']=$this->Home_Model->displayVideosAll($cat);
$this->load->view('header');
$this->load->view('doupnow-video-more', $result);
$this->load->view('footer');
}
Now when i navigate to "http://doupnow.com/morevideo/latest", this page getting the parameter correctly and also displaying the data based on the parameter only but the view is not getting the html and css elements like the other pages.
Kindly give me the proper direction. Thank You.
On your site, when you're linking to a script or stylesheet, you link it by doing:
/js/script.js
But you need to give the full url like this:
http://doupnow.com/js/script.js

main page of Codeigniter not found

I have a problem with my CI project in my linux server (there is no problem in windows wamp),
in my project every route works fine except main page (address http://example.com without any query string), that shows 404 error.
here my configs :
htaccess :
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Options -Indexes
php_flag output_buffering On
my routes.php :
$route['default_controller'] = 'index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['index'] = 'index/index';
$route['/'] = 'index/index'; // i have controller index.php and action index for first page that load with address example.com/index/index
my config.php:
$config['base_url'] = 'http://example.com';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; //and "REQUEST_URI" both tested.
any help would be appriciated.
This problem of "it works on Windows but not on Linux" is almost always due to incorrect file naming. It appears your 'default_controller' class is named "index". Both the file name and the class declaration MUST use an uppercase first character.
In other words, the file must be Index.php (note the uppercase I) and the declaration must be
class Index extends CI_Controller
Again, note the uppercase "I" in Index.
All that said, CodeIgniter documentation clearly states that a controller should NOT be named Index. So, pick some other name.

i need to change the default page of codeigniter website

i have a codeigniter website
even the default controller is Welcome
http://www.immodernafrican.com/index.php/Welcome
but this website is not opening on http://www.immodernafrican.com can anyone help me regarding this issue
Thanks
Regards
Please insure your controller file name first character Uppercase Welcome.php
and can insure your $route['default_controller'] = "Welcome";
Class names must start with an uppercase letter.
This is valid:
<?php
class Welcome extends CI_Controller {
}
This is not valid:
<?php
class welcome extends CI_Controller {
}
Also .htaccess copy and paste :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Also insure $config['uri_protocol'] = 'AUTO'; in application/config/config.php file

url_suffix in codeigniter not working properly

I am new to Codeigniter and using Codeigniter 1.7, I created a .htaccess file in root directory with code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
to remove index.php from urls, and added
$config['url_suffix'] = ".html";
to config.php file to provide default suffix for all pages. After that I created a controller test.php with this code:
class Test extends Controller{
function test(){
parent::Controller();
}
function index(){
$this->load->view('test');
}
}
and a view also:
<?php
echo anchor(current_url(), 'This Page');
?>
When I navigate to http://localhost/ci/test.html it works fine, but when I click the link auto generated by anchor() function in my view it goes to http://localhost/ci/index.php/test.html
How can I remove /index.php/ from urls generated by anchor() function?
Also when i point to home page
localhost/ci/index.html
it shows me a 404 Page not found error but when I point to
localhost/ci/index.php
it works fine. Why home page is not being converted to index.html instead of index.php?
You have to create a rewrite condition with htaccess.
To remove index.php, add this to the root folder .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*) /index.php/$1 [L]
If your loading Test as your default controller then this will be your base url
localhost/ci/
or
localhost/ci/test/
or
localhost/ci/test/index.html
Make sure to set your config.php to this
$config['index_page'] = ''
You should also be using Codeigniter 2.1 for proper php 5 support.
Also your constructor funciton should be like so if using php 5. Else stick with what you have for php 4.
public function __construct()
{
parent::__construct();
}

Resources