Code Igniter doesn't recognize my function in controller under a folder - codeigniter

I have a folder under my main controller-folder called admin, in that controller i have a file name admin.php which has a function xyz.
I want to access that function using this url
http://localhost/webroot/admin/xyz
However when I try to access it, it is giving me this error.
404 Page Not Found
The page you requested was not found.
this is code of my routes.php file
$default_controller = "welcome";
$controller_exceptions = array('welcome','forum');
$route['default_controller'] = $default_controller;
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
$route['404_override'] = '';
$route['admin'] = "admin/admin";
This is my .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Also mod-rewrite is enabled :)
Please let me know why is it not working and how can i make it work. Any kind of help is really appreciated. Thanks

Ensure that your routes are stored in application/config/routes.php (not router.php as specified in your question). Try adding a route that uses a wildcard, like this:
$route['admin'] = "admin/admin"; //Routes to 'index()' function
$route['admin/(:any)'] = "admin/admin/$1"; //Handles all other cases
:any will match a segment containing any character(s), after the admin segment, and will pass it/remmap it to the the admin controller.
The user guide contains more information on controllers in sub-folders and routing.

Related

CodeIgniter model works in localhost not in live

Every thing works fine in localhost, but when I upload on server, login view is getting opened but, while in checklogin when I try to load model I am getting bellow error
Unable to locate the model you have specified: loginmodel
controller file: login.php
class Login extends CI_Controller {
public function checkLogin() {
$this->load->model('loginModel');
....
model file: loginModel.php
class LoginModel extends CI_Model {
config file
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'http://myattendance.co.nf/';
.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# FOR LIVE
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
# FOR LOCAL
#RewriteRule .* index.php/$0 [PT,L]
</IfModule>
Codeigniter 3+ requires First letter of your class file capital in linux machine. I think your live server is a linux machine and you are developing in windows machine. Just simply rename all of your class files (Controller, Model and Libraries) to first letter capital. eg: rename your model loginModel.php to LoginModel.php
Hope this would solve your problem.
php version may be different on server and local so please make class name and file name same. for example If Your class LoginModal then its file name should be LoginModal.php also same for controller class.
Change the model's file name, model file: loginModel.php to model file: Loginmodel.php,then change the name of the model's class name as well from class LoginModel extends CI_Model{} to class Loginmodel extends CI_Model{} then refresh your link, it will work.

Laravel 4.2 rewrite URL - remove public

My old domain: domain.com
My laravel project in: domain.com/laravel/public
It's working well, but I don't want see public in URL.
I add new .htaccess file to my root laravel folder (domain.com/laravel/.htaccess) with:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
When I access to domain.com/laravel, my jQuery path is: domain.com/js/jquery.min.js
When I access to domain.com/laravel/public, my jQuery path is: domain.com/laravel/public/js/jquery.min.js
I don't want move all files in public folder to root folder, because really more files there.
Best regards,
I read more answers in more website, almost their said move all files in public folder to root folder of Laravel application.
It's not good if we have more files there, so, I was try with some way and finally, I just move index.php and .htaccess file to root application.
It's working well, I just change some code when using HTML::script, HTML::css and {{ asset }}
As normal, we using HTML::css('style.css'), I just add public before, like this: HTML::css('public/style.css')
I hope it helpful for someone.
Best regards.
This is my current solution:
<IfModule mod_rewrite.c>
RewriteCond $1 !^(public)
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
You have to add a rewrite condition.

Laravel Routing Does not Work

I am new in LARAVEL framework and I want to run a controller with just function of view a page
class TestController extends BaseController {
public function index()
{
return View::make('hai');
}
}
I set the routing in routes.php file as given below
Route::get('test','TestController#index');
I tried to run in mozilla with
localhost/laravel/public/test
but it shows
Not Found
The requested URL /laravel/public/test was not found on this server.
is there any problem in my .htaccess page ?
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Any body please help me.
I'm assuming that you are on Ubuntu machine. To make it work, at first, enable the rewrite module by executing following command in the terminal
sudo a2enmod rewrite
Second, find "apache2.conf" file in your system, mine is located in
/etc/apache2/apache2.conf
In this file, find the following snippets of code:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change "AllowOverride None" to "AllowOverride All". Save the file and restart the apache server by executing following command
sudo service apache2 restart
This should solve the issue. Cheers
Precondition: you will know that you have htaccess working, if when you first installed laravel and went to localhost/laravel/public/, you'd see the laravel logo.
The route is:
Route::get('/', function()
{
return View::make('hello');
});
Regarding Your route: you don't need to explicitly state the function (#index) in the route. Laravel has a default path it follows based on the HTTP request type. Check here (under the heading Actions Handled By Resource Controller) for more details on that.
Simply I refer you not modifying .htaccess file. From http://tisuchi.com/easy-way-handle-routing-laravel/:
Static Page Handling
Handling static page in laravel is one of the easiest way to handle
route. Open app/routes.php file and deleted everything from that.
Assume that, we are try to route into our following pages- home
(example.com), about (example.com/about), contact
(example.com/contact). To do so, just write following code in your
routes.php file-
/**
* Static page code
*/
Route::get('/', function(){
return View::make('home');
});
# For example.com/about
Route::get('about', function(){
return View::make('about');
});
/**
* Naming Route for static Page
*/
# For example.com/contact
Route::get('contatct', array('as' => 'contact', function(){
return View::make('contact');
}));
If you are really new in Laravel, highly recommend to look into following 2 tutorials-
http://freshwebdev.com/best-laravel-tutorial-beginners.html
http://tisuchi.com/easy-way-handle-routing-laravel/
Ofcourse, don't forget to take a look into official page of laravel.com.
Hope, it will work for you.
Have fun...

Configuring MODx Revolution to work with both http and https

I have a website using MODx Revolution (2.2.10-pl, advanced install), let's call it www.example.com, which I want to be accessible with both http and https.
to achieve this, I tweaked the site_url context setting to be [[++url_scheme]]www.example.com/. Links created using [[~id]] seem to be alright, however, sometimes, the generated links are really weird. My interpretation is that the code to create links programmatically doesn't work with my settings, but I don't know why, or how else I would go about enabling both http and https.
Question first, examples below: How should I set the site_url or any other site/context setting so that links on my site work with both http and https? Optionally, is the behavior I see a bug, or expected behavior given Revolution's tag evaluation semantics?
Misbehavior examples:
When I click on "View" in the manager for a resource with the alias example, the address that is opened is
https://www.example.com/xyz/[[++url_scheme]]www.example.com/example/
where xyz is my manager URL. The expected URL is of course
https://www.example.com/example/
Another case where this happens is for failed logins; my login call looks like this (minus irrelevant parts):
[[!Login? &redirectToOnFailedAuth=`[[++unauthorized_page]]`]]
The unauthorized_page's expected full URL is
https://www.example.com/special/401
but the URL which is opened for a failed login as username is
https://www.example.com/[[++url_scheme]]www.example.com/[[++url_scheme]]www.example.com/special/401?u=username
The second example is the same for http, except for the scheme, of course; I haven't logged into the manager with http.
EDIT
.htaccess at the webroot:
RewriteEngine On
RewriteBase /
# redirect all requests to /en/favicon.ico to /favicon.ico
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/favicon.ico$ favicon.ico [L,QSA]
#RewriteRule ^(en|nl|de)/favicon.ico$ favicon.ico [L,QSA]
# redirect all requests to /en/assets* /assets*
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/assets(.*)$ assets$2 [L,QSA]
#RewriteRule ^(en|nl|de)/assets(.*)$ assets$2 [L,QSA]
# redirect all other requests to /en/*
# to index.php and set the cultureKey parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
#RewriteRule ^(en|nl|de)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
.htaccess in the manager's directory:
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/xyz/$1
The problem is with $modx->makeUrl(). For example, for the
[[!Login? &redirectToOnFailedAuth=`[[++unauthorized_page]]`]]
call, in core/components/login/controllers/web/Login.php:
public function checkForRedirectOnFailedAuth(modProcessorResponse $response) {
$redirectToOnFailedAuth = $this->getProperty('redirectToOnFailedAuth',false,'isset');
if ($redirectToOnFailedAuth && $redirectToOnFailedAuth != $this->modx->resource->get('id')) {
$p = array(
'u' => $this->dictionary->get('username'),
);
$message = $response->getMessage();
if (!empty($message)) $params['m'] = $message;
$url = $this->modx->makeUrl($redirectToOnFailedAuth,'',$p,'full');
$this->modx->sendRedirect($url);
}
}
the last two lines do a redirect to a URL generated with makeUrl, which will be something like [[++url_scheme]]www.example.com/etc (note: I'm not 100% sure here, as I can't easily look at the raw URL. The conclusions still hold, though). If the URL is simply shown on the page, this is no problem, because MODx will parse the tag before inserting it into the html output. However, as the URL is used directly for the redirect, no such replacement takes place, and the browser interprets it as a relative URL, resulting in target URLs such as https://www.example.com/[[++url_scheme]]www.example.com/etc.
So much for the problem. To avoid this, site_url must be a literal value without any tags in it. As a workaround, I now use the following snippet as the first thing in my template:
$modx->config['site_url'] = $modx->config['url_scheme'] . substr($modx->config['site_url'], strlen('[[++url_scheme]]'));
return '';
together with a [[++site_url]] of
[[++url_scheme]]www.example.com/
Note that some parts of MODx don't seem to notice this update, which is why it's important to still use [[++url_scheme]] in your site_url. As far as I can tell right now, the parts that don't see the update, stuff like [[~id]], work properly with url_scheme.
EDIT this does of course only fix the "View" buttons in the manager if you tweak the manager templates accordingly.
WARNING this is of course very hacky, and not yet tested very well. The fact that some features do not see the overwritten value means that you're introducing an inconsistency into your website, which may lead to subtle errors! If a more clean solution comes up, go for it!

Codeigniter URI Segment Not Working properly online

Please have a look at the following url:-
English: http://www.santinepal.com/demo/en
Nepali: http://www.santinepal.com/demo/np
The codeigniter profiler is ON but it shows
URI STRING
No URI data exists
The $this->uri->segment(1); shouldve returned en or np but it reruns nothing.
This works fine on my localhost.
my routes.php file has:-
$route['default_controller'] = 'front';
$route['backend'] = 'backend/sentry';
// URI like '/en/about' -> use controller 'about'
$route['^(en|np)/(.+)$'] = "$2";
// '/en' and '/fr' URIs -> use default controller
$route['^(en|np)$'] = $route['default_controller'];
Check that your .htaccess file is the same on the server and that URL Rewriting is enabled.
Navigating to http://www.santinepal.com/demo/index.php/en shows the URI segments working, so it must be server configuration issue.
I've had something similar, turns out some server setup caused the issue. Try changing your .htaccess file that removes the index.php to this:
#CODE IGNITER - REMOVE INDEX.PHP
RewriteCond $1 !^(index\.php|resources|file_uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
The last line is the only one that is different, there is a ? after the index.php.

Resources