I started with a phalcon project and used this tutorial (https://docs.phalcon.io/3.4/en/tutorial-base#basic). But i've got a problem with my controllers.
In my index controller i have:
echo $this->tag->linkTo(
'signup',
'Sign Up Here!'
);
But when i click on Sign Up Here! i get the error message "The requested URL /signup was not found on this server."
I think it has something to do with this part of code, but it looks correct to me.
$di->set(
'url',
function () {
$url = new UrlProvider();
$url->setBaseUri('/');
return $url;
}
);
It's not even showing my exception
$application = new Application($di);
try {
// Handle the request
$response = $application->handle();
$response->send();
} catch (\Exception $e) {
echo 'Exception: ', $e->getMessage();
}
I followed the tutorial on youtube as well and did everything in exact the same way as he did in the video. So i was wondering if anyone can help me out here.
file structure
Thanks
Looks like you are missing the main .htaccess file in the public folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
And this could be the reason why the exception is not being generated.
Related
I'm watching a tutorial video from youtube about making simple route project with just php and I did exactly what he did but there is an error in my project and I can't fix that . when I'm trying to write 'about' or 'contact' the webpage went to object not found! error
Object not found!
The requested URL was not found on this server. If you entered the URL
manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.5
by the way I'm using xampp
This is my route class
class Route{
private $_uri = array();
/**
* Builds a collection of internal URL's to look for
* #param $uri
*/
public function add($uri){
$this->_uri[] = trim($uri,"/");
}
public function submit(){
$uriGetParam = isset($_GET['uri']) ? $_GET['uri'] : "/";
foreach ($this->_uri as $key => $value){
if (preg_match("#^$value$#",$uriGetParam)){
echo "Match!";
}
}
}
}
This is my php code (index)
include "route.php";
$route = new Route();
$route->add("/");
$route->add("/contact");
$route->add("/about");
$route->submit();
And finally this is my .htaccess file
RewriteEngine On
RewriteBase /route/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
I'm learning Slim Framework and got stuck with its routing.
Working Code. Code snippet #1:
$app = new \Slim\App();
$app->get("/", function () {
echo "Hello SlimFramework";
});
$app->run();
Not Working. Code snippet #2:
$app = new \Slim\App();
$app->get("/hello/{name}", function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
I'm getting "Not Found
The requested URL /hello/name was not found on this server." for Code snippet #2. Any clue what's going on here ?
.htaccess File
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Thanks in advance !
I had to start with clean slate in order to solve this issue for me. #ceejayoz's solution about making sure if .htaccess is working correctly, was a great help to test .htaccess configuration.
I am working on the E-Commerce site and use CodeIgniter framework in PHP.I have two panels: 1) front and 2) Admin.
During page load or URL redirection if 'Internal Server Error' occur, I want to display my custom design page 500_error_admin.php for admin and 500_error_front.php for front UI.
Let me clear 500_error_admin.php and 500_error_front.php both pages have different design.
I try this code but I can't get success
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
#Directly give the path of page
ErrorDocument 500 http://localhost/myproject/errors/500_admin.php
#Also try with create controller and call method
#ErrorDocument 500 http://localhost/myproject/admin/Error/show_500
</IfModule>
Controller Method
class Error extends CI_Controller {
function __construct() {
parent::__construct();
}
function error_500() {
$this->load->view('errors/500_admin');
}
}
Is this possible in codeigniter which i looking for?
Please suggest me, how can i do it with alternative ways?
You can archive by owerride core exaption controller for both admin side and client side, follow the given steps:
Step:1 Add subclass prefix: $config['subclass_prefix'] = 'MY_'; in your config file(system/application/config/config.php)
Step:2 Create MY_Exceptions.php file in you directory(system/application/libraries) and add bellow code
class MY_Exceptions extends CI_Exceptions{
function MY_Exceptions(){
parent::CI_Exceptions();
}
function show_404($page=''){
$this->config =& get_config();
$base_url = $this->config['base_url'];
$_SESSION['error_message'] = 'Error message';
header("location: ".$base_url.'error.html');
exit;
}
}
Thats it! Not your error page will redirect to the error.html page. Hope this will help you!
Greetings!
You can make your custom page for showing error. codeigniter 3 already has default error page. if you want to change error page then open config.php inside application/config/config.php
Inside config.php find Error Views Directory Path
$config['error_views_path'] = APPPATH.'/views/errors/'; //path to you error view directory
then change to you directory error views. inside views there is 2 directory.[cli,html]
where cli view handle while you access your website throught cmd or terminal.
and html view handle while you access your website throught browser.
in this case you need to change design for html.
inside html there is 5 error page defined by ci.
-application/views/html/error_404.php // while page doesn't exist
-application/views/html/error_db.php // while error on db such as configuration and etc
-application/views/html/error_exception.php // error exception
-application/views/html/error_general.php // error general
-application/views/html/error_php.php
you can change your 500_admin.php rename 500_admin.php to error_general.php. for the variable message you need to open default error_general.php and paste into your new view
remember put them inside application/views/errors/html.
so your error page structure folder will be look like this
application/views/errors/html/error_general.php
for detail explanation you can see the documentatuion here
myproject/application/config/database.php
SET $db['default']['db_debug'] to FALSE instead of TRUE .
$db['default']['db_debug'] = FALSE;
This is a old question, but this is my solution:
in application/core
<?php
class MY_Exceptions extends CI_Exceptions
{
public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
$message = '<p>'.(is_array($message) ? implode('</p><p>', $message) : $message).'</p>';
$_SESSION['500_error_heading'] = $heading;
$_SESSION['500_error_message'] = $message;
redirect('error/server');
}
}
in config/routes.php
$route['error/server'] = 'errorController/error_server';
in errorController
public function error_server()
{
$session = new SessionHelper();
$data['heading'] = $session->get('500_error_heading');
$data['message'] = $session->get('500_error_message');
$session->unset('500_error_heading');
$session->unset('500_error_message');
$this->CI->load->view_template('errors/html/error_general', $data);
}
define('ROUTE_BASE', 'lumen/public');
$app->get(ROUTE_BASE . '/', function () use ($app) {
return $app->welcome();
});
$app->get(ROUTE_BASE . '/test', function () use ($app) {
return 'test data : 123 abc !';
});
When I access 'localhost/lumen/public/' I can see the 'lumen welcome page'.
But if I try to access 'localhost/lumen/public/test', I receive the following error.
Error: its not found(404).
Laravel expects the public directory to be the webroot of your domain. As this is not true in your case, you will need to make some alterations to your .htaccess.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /lumen/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Also worth noting that instead of using a constant, you can use route groups to achieve the same functionality in your routes.php.
$app->group(['prefix' => 'lumen/public'], function ($app) {
$app->get('/', function () {
//welcome
});
$app->get('test', function () {
return 'test data : 123 abc !';
});
});
your lumen project must be put in webroot of your localhost,domain or virtual host not in subfolder of your webroot without edit your .htaccess.
for access your project in browser : http://lumen.laravel.dev not http://lumen.laravel.dev/public/
I hope this help. sorry for my English :)
I have installed CodeIgniter_2.1.3 and running in
Windows 7
Wamp Server 2.1
PHP 5.3.5
Apache 2.2.17
In \applicationconfig\routes.php, I created
$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['products/catlog'] = "welcome/getOneMethod";
And in \application\controllers\welcome.php, I created a method
public function index()
{
$this->load->view('welcome_message');
}
public function getOneMethod()
{
echo "hi im in newMethod";
}
http://localhost/CodeIgniter_2.1.3/products/catlog
Now I expect on running this url above on browser to give me the page
hi im in newMethod
But instead i'm getting the error message.
Not Found
The requested URL /CodeIgniter_2.1.3/products/catlog was not found on
this server.
What should i do to make it work correctly?
Doo you visit codeigniter documentation website,You can get help from this url how to create static pages
http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html
For the given url routes and controller.
you will need to use:
http://localhost/CodeIgniter_2.1.3/index.php/products/catlog/
The index.php part in the url can be removed using htaccess rewrite rule.
In the /codeigniter2.1.3/ folder create an .htaccess file and put the following rule:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CodeIgniter_2.1.3/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /CodeIgniter_2.1.3/index.php [L]
</IfModule>
Note: This might not be the best way to do it.
EDIT:
Make sure the controller is exactly as bellow,
class Welcome extends CI_Controller {
public function index() {
$this->load->view('welcome_message');
}
public function getOneMethod() {
echo "hi im in newMethod";
}
}
and the routes are as bellow:
$route['default_controller'] = "welcome";
$route['404_override'] = '';
$route['products/catlog'] = "welcome/getOneMethod";
For the time being remove the htacces, and make it work with index.php in url.
ie:
http://localhost/CodeIgniter_2.1.3/index.php/products/catlog/
Note: since you are able to see the welcome message, there is no problem with your installation or server. there is probably some syntax error. so i recommend you copy paste the above code, as i have checked them and they are working.