In my dashboard all the css and js are getting applied, but when i call a function from other controller then the css and js will not get applied.
My code from view is - File sidebar.php:
<li><i class="fa fa-circle-o"></i> Add Farm</li>
And controller is - farm.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Farm extends CI_Controller {
public function index()
{
$this->load->view('farm_info');
}
public function add_farm()
{
$this->load->view('farm/add_farm');
}
}
Also my .htaccess file contain
# If your default controller is something other than
# "welcome" you should probably change this
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ /index.php/$1 [L]
Please help me with this, i will provide you any other info if you want
Related
I have old urls like http://example.com/products.php?s_productid=231 and now in my proyect whit url would be http://example.com/products/ver/231
How can I make a rule in routes.php to redirect?
Thanks
you don't need to do any change in routes.php, all you need is to create a Controller "Product", with one Method "ver", which receives 231 (it's id I guess) as a parameter, like this:
defined('BASEPATH') OR exit('No direct script access allowed');
class Product extends CI_Controller {
public function __construct(){
parent::__construct();
}
public function ver($id) {
// do your things
}
I hope it helps.
You may need to set the routes in config/routes.php
$route['product/ver/(:num)'] = 'product/ver/$1';
http://example.com/index.php/products/ver/231
Then the controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Product extends CI_Controller {
public function __construct(){
parent::__construct();
}
public function ver($id) {
/*
echo $id;
*/
}
I have built a website with the CodeIgniter framework.
Unfortunately, I am having a problem with CodeIgniter's load->view() function.
Every time I try to load another view file with the code $this->load->view('any_view_file'); I get the error:
unable to load the requested file 'any_view_file'.php
For example i am having problems with the $this->load->view('available_lessons.php', $data); command. So let's try to recreate the problem and think this through...
I am calling the load_available_lessons() function of the Lessons.php controller
The load_available_lessons() function uses the get_lessons() function of the db_model.php model and saves the result on the $data['result'].
Then, the load_available_lessons() function calls the available_lessons view file while parsing the $data to it.
Here is where the problem rises. CodeIgniter is unable to load the view. As i explained earlier, CodeIgniter fails to load any view...!!!
Any suggestions please?
My .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\\.php|images|css|lessons|robotos\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
From my config.php file:
$config['index_page'] = '';
From my routes.php file:
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['translate_uri_dashes'] = TRUE;
My Pages.php Controller:
<?php
class Pages extends CI_Controller {
public function view($page = 'home')
{
if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
else
{
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
}
?>
My Lessons.php Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Lessons extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('db_model');
/* $this->load->library('acl'); */
/* $this->load->helper(array('form', 'url')); */
}
public function index()
{
$this->load->view('available_lessons', array('error' => ' ' ));
}
public function load_available_lessons()
{
$data['result'] = $this->db_model->get_lessons();
$this->load->view('available_lessons.php', $data); /* available_lessons */
}
}
?>
My db_model.php Model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class db_model extends CI_Model{
public function __construct()
{
parent::__construct();
}
public function new_lesson($data)
{
/* Inserting in Table "lessons" of CodeIgniter's Database */
$this->db->insert('available_lessons', $data);
}
public function get_lessons() /* $data */
{
/* Get lessons from Table "lessons" of CodeIgniter's Database */
$this->db->select('Name, Description, DateAdded, LastEdit, UserID, FileName');
$this->db->from('lessons');
$query = $this->db->get();
return $result = $query->result();
}
}
?>
My available_lessons.php View file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div class="container">
<h6 class="description">Browse Lessons</h6>
<div class="row">
<section id="lessons-panel" class="col-xs-12 col-md-8 col-md-offset-2">
<table>
<tr>
<th>Content</th>
</tr>
<?php foreach($this->result as $r): ?>
<tr><?php echo $r->content; ?>
</tr>
<?php endforeach; ?>
</table>
</section>
</div>
</div>
As #ourmandave and a coworker pointed out to me, i should add the "pages/" before every view name that i want to call. For example, in the Lessons.php controller, i should have $this->load->view('pages/available_lessons.php', $data); As it turned out he is right.
The thing is that i cannot understand the reason why i should include the "pages/" as I have already included this in the Pages.php controller. It seems that the Pages Controller is not being used when i call a view. I will have to look into it later on.
Thank you all for your valuable input!!!!! Just another rookie mistake...
my controller `
class index extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('html');
$this->load->helper('url');
$this->load->helper('form');
}
public function index()
{
$this->load->view('login');
}
` public function home()
{
$this->load->view('header');
$this->load->view('index');
$this->load->view('footer');
}
}
the url of function home in this controller is this
http://localhost:88/mlmm/index.php/index/home
i want this url to be
http://localhost:88/mlmm/home
To remove index.php from your URL you need to add .htaccess file and below code inside that.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
for making url like this http://localhost:88/mlmm/home you need to mention routes in your config/routes.php file
$route['home'] = 'index/home';
Note : you have mention the controller name index and in codeigniter by default controller first method is also index so this can be make problem so I suggest use different controller name.
I want to extend CI_Controller as a base class for my other classes according do my own need.
I read the user guid. Acted as what it told me.
I created application core:
./application/core/MY_ControllerPermission.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_ControllerPermission extends CI_Controller
{
function __construct()
{
parent::__construct();
}
}
And this is my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if(class_exists('MY_ControllerPermission'))
echo 'clase does exist';
else
echo 'clase does not exist';
class Users extends MY_ControllerPermission
{
....
In my config file:
$config['subclass_prefix'] = 'MY_';
It just show blank page and "clase does not exist"
So where is the problem?
UPDATE
If I add this line:
include_once(APPPATH . 'core/MY_ControllerPermission.php');
before my controller, it would work. Doesn't CodeIgniter load core PHP files automatically?
Rename MY_ControllerPermission.php to MY_Controller.php and you should be good to go.
You can leave everything else the same, you don't even need to use the name MY_Controller for your class if you don't want to.
After i had changed my codeigniter files to another hosting it come out with this error.
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects
It might cause by the infinity looping redirect in my code but i cant figure it out whats the error in my code
my route default controller is inside.php
here is the inside.php (controller) code
class Inside extends Controller{
function __construct(){
parent::Controller();
$this->loginchk_model->is_logged_in();
}
function index(){
$this->template->write('title', 'Update to date data');
$this->template->write_view('header', 'header_content', true);
$this->template->write_view('content', 'inside_view', true);
$this->template->load();
}
}
and here is the loginchk_model.php (model) code
class Loginchk_model extends Model{
function is_logged_in(){
//check session exist or not
if($this->session->userdata('is_logged_in') && $this->session->userdata('username')){
redirect('inside');
die;
}else{
redirect('login');
//echo anchor('login','Back to login page');
die();
}
}
}
and here is the login.php (controller) code
class Login extends Controller{
function __construct(){
parent::Controller();
$this->load->helper('form');
$this->load->model('his_action_model');
}
function index(){
$data['title'] = 'Login in';
$this->load->view('login_view', $data);
}
here is my htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /foldername/index.php/$1 [L]
</IfModule>
Stuck for few hours in this problem.. i am also wondering why changed hosting cause such problem.
thanks in advanced!
That issue could be because of your .htaccess I believe I had that issue before when going from local server to my host. There was extra lines at the bottom of the .htaccess that were causing an issue on that particular server so I commented them out. But I could be wrong.
Is this happening for just you or have you tried viewing the error from a different PC?