Codeigniter routing strange 404 error - php

I have a problem with codeigniter routing.
I can't understand at all, what's wrong.
I have a rule in my routes.php file:
$route['multimedia/(:any:)'] = 'multimedia/$1';
$route['multimedia'] = 'multimedia/index';
So, if I go to http://mywebsite.com/multimedia - all is works well , but if I go to http://mywebsite.com/multimedia/hello I get 404 Error.
This is a part of my multimedia controller:
<?php
class Multimedia extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('multimedia_model');
$this->load->helper('language');
$this->load->helper('form');
}
public function index(){
//............This works
}
public function hello()
{
//..........This not works
}
}
The most strange thing to me, that I have another same rule in routes.php file,
$route['popup/(:any)'] = 'popup/$1';
$route['popup'] = 'popup/index';
which is works well when I go to mywebsite.com/popup and mywebsite.com/popup/hello
Anybody, please, help me, what's wrong??

$route['popup'] = 'popup/index';
$route['popup/(:any)'] = 'popup/$1';
(:any) specification should only be called only after all other constraints.
Try this...

Related

Unable to load the requested file in Codeigniter

Everything is working fine on my Localhost(Xampp) but when i upload the same code on Server(cPanel) then it is giving me error Unable to Load the Requested File
Controller:
class Industries extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function view_industry($id) {
$data['view_industry'] = $this->Industry_model->view_industry($id);
$data['main_view'] = "Industries/view_industry";
$this->load->view('templates/main', $data);
}
}
Route:
$route['view_industry'] = "Industries/view_industry";
View :
What could be the reason??? because the same code is working absolutely fine on LOCALHOST.
Actually the CASE was the issue.
For example Industries != industries
Thanks Guys.

Error:404 page not found, code igniter

controller.php
<?php
define('_root',$_SERVER['DOCUMENT_ROOT']);
include(_root.'/innoshop/application/models/model.php');
// include_once 'model.php';
class Controller {
public $model;
public function __construct()
{
$this->model = new Model();
}
If i put localhost:8888/projectname, i got error like this
404 Page Not Found
The page you requested was not found.
anyone help me
As the guys say you should read the docs as this is very wrong. To fix do this..
class Controller extends CI_Controller{//better to give your controller a more meaningful name
public function __construct(){
parent::__construct();
//use the CI loader - the model will then be available like this $this->model->some_function();
$this->load->model('model');//better to give your model a more meaningful name as well
}
//the index method allows you to use just the controller name in your URI eg localhost:8888/projectname/index.php/controller
public function index(){
echo 'something to see';
}
//an alternative controller method get it like localhost:8888/projectname/index.php/controller/your_method_name
public function your_method_name(){
echo 'something to see in your method';
}
}
If you want rid of the index.php in the URI search for questions related to .htaccess in CodeIgniter
If you want to be able to use a uri like this localhost:8888/projectname then you need to add a route in config/routes.php that defines the default controller like this $route['default']='controller';

controller name in the url in codeigniter to be more than one

I have 3 controllers are home, food, and drink. home controller I want to make the default controller. and I wrote in routes.php file like this:
$ route ['default_controller'] = "home";
$ route ['404_override '] ='';
then i made the code in each controller as below:
controller home.php
class Home extends CI_Controller{
public function __construct() {
parent::__construct();
}
public function index(){
}
public function info(){
}
}
controller food.php
class Food extends CI_Controller{
public function __construct() {
parent::__construct();
}
public function index(){
}
public function foodMenu(){
}
public function foodJenis(){
}
}
controller drink.php
class Drink extends CI_Controller{
public function __construct() {
parent::__construct();
}
public function index(){
}
public function drinkMenu(){
}
public function drinkJenis(){
}
}
I want to make this url like www.mydomain.com/home, www.mydomain.com/food, www.mydomain.com/food/foodmenu, www.mydomain.com/food/foodjenis, www.mydomain.com/drink, www.mydomain.com/drink/drinkmenu, www.mydomain.com/drink/drinkjenis.
but when I was on the url www.mydomain.com/food/foodmenu and I headed to www.mydomain.com/food/foodjenis, but the url that appears is www.mydomain.com/food/food/foodjenis. "food" controller name in the url it into two. how to handle it. please help me. thank you :(
One way to solve is through the use of base tag.
Somewhere in the document head (before including any css or js) put
<base href='http://mysite.com'>
After that you can freely use relative links in your CI applications.
How do u make your links?
I think there is problem u try to make relative linking and html is looking at food as a folder so when u make link as
it will make link as u wrote www.mydomain.com/food/food/foodjenis
But if u use CI url
It shall work like u intended.
did you set base url in config file in CI ?If yes. try with relative paths. like food/foodjenis

codeigniter route does not route as expected

in php word "list" is reserved so i had to use "listby" and create route.
According to CI User Guide I have created a route as follows:
$route['list'] = "listby";
It's routing perfectly the index function with url like "http://myserver.com/list" but does not route other functions i.e.. "http://myserver.com/list/uuid".
Here's contorller code:
class Listby extends CI_Controller
{
public function index()
{
echo "index";
}
public function userid()
{
echo "userid";
}
public function uuid()
{
echo "uuid";
}
}
Side note: with url like "http://myserver.com/listby/uuid" works fine.
Any clues where is the problem?
try:
$route['list/(:any)'] = "listby/$1";

Default RESTful CakePHP routing gives Missing Controller Method error

I am following this tutorial http://book.cakephp.org/2.0/en/development/rest.html to get up and running with REST in my CakePHP application.
I have added the following to my routes.php file:
Router::mapResources(array('fantasyPicks', 'fantasyPlayers'));
Router::parseExtensions();
In each of my controllers, I have included the RequestHandler component and also setContent to json in the beforeFilter() callback. It looks something like this:
class FantasyPicksController extends AppController {
public $components = array('RequestHandler');
public function beforeFilter() {
parent::beforeFilter();
$this->RequestHandler->setContent('json','text/x-json');
$this->layout = 'json/default';
}
public function index() {
$fantasyPicks = $this->FantasyPick->find('all');
$this->set('json', $fantasyPicks);
$this->render('/json/data');
}
...
My json/data view simply echos json_encode:
<?php echo json_encode($json); ?>
After all of this, navigating to /fantasyPicks/view/1 works as expected. However, /fantasyPicks/1 is giving me the following error:
Missing Method in FantasyPicksController
Error: The action 1 is not defined in controller FantasyPicksController
Error: Create FantasyPicksController::1() in file: app\Controller\FantasyPicksController.php.
<?php
class FantasyPicksController extends AppController {
public function 1() {
}
}
Does anyone know what I am doing incorrectly? Any help is appreciated!
You have to use proper controller naming conventions when accessing the page.
http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html
Refer to the URL considerations section. So you should be going to /fantasy_picks/1 and it will work properly.

Categories