-
Notifications
You must be signed in to change notification settings - Fork 0
Codeigniter
Vital-jan edited this page Aug 23, 2022
·
6 revisions
for remove "index.php" from address bar:
Create .htacess in root folder, above application folder and type:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
You must type in bash to activate rewrite module: sudo a2enmod rewrite
application/config/config.php:
$config['base_url'] = ''; or $config['base_url'] = $_SERVER['HTTP_HOST'].'/';
$config['index_page'] = 'index.php'; $config['log_threshold'] = 0; - уровень ошибок, записываемых в лог.
файл application/config/database.php - add to .gitignore
Rename application and system folders, then change settings in the index.php in the root of project
Start project:
создаем шаблоны header.php и footer.php в views/templates
создаем страницу {page}.php в views/pages
создаем контроллер Page.php в controllers и помещаем в него:
<?php
class Page extends CI_Controller {
public function view($page = 'page')
{
if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
show_404();
}
$data['title'] = "My title ...";
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
Доступ к странице: {host_name}/index.php/{class_name}/{method_name}
apache2.conf:
<Directory /{host_path}>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Маршрутизация:
config/routes.php:
$route['default_controller'] = 'page/view'; //{class_name}/{method_name}; - главная страница
$route['{url}'] = '{class_name}/{method_name}';