Kohana 3 - Redirect to other localhost project - php

$this->request->redirect('localhost/project2/');
From a controller in project1, I have this code, but it's always redirecting me to localhost/project1/index.php/localhost/project2. How can I properly redirect to localhost/project2/ ?
I tried using header() to redirect but its not working in Kohana. Im using Kohana 3.2 in PHP 5.5.12

You should use http before link to specify it is a complete URL:
$this->request->redirect('http://localhost/project2/');
And you shouldn't use the localhost as a static text in your code because your server will changed, you should use on of the ways to return your server root like $_SERVER['HTTP_HOST'] or if you use a MVC framework you can use its function that return base URL.

Related

Redirect to Laravel framework page

I need to redirect from a CGI to a page of the same server created in Laravel. When I use the path from a browser it presents itself without problems, but when using the CGI, Laravel presents an error to me.
https://myserver:8080/bitacora/index.php/devices
Error when using Location: /bitacora/index.php/devices header from a CGI
The only difference I see in PHP is that it does not use QUERY_STRING, but the "arguments" are delivered by the PHP_SELF variable.
Any ideas on how to act correctly? I remember that some frameworks redirect to a variable, such as module or action. Something similar in Laravel?
Use full URL
not just
Location: /bitacora/index.php/devices
But replace this with following
Location: http://myserver:8080/bitacora/index.php/devices.

Yii2 web url without using setAlias

I have a Yii2 app but no ability to edit the config files to utilize setAlias.
If my domain is example.com, and my Yii application is in /my-app directory, then what would be the Yii command to return the following string:
http://example.com/my-app/
Yii::getAlias('#app') returns
/httpdocs/my-app
Many posts exist but all I've found is suggestions either based on Yii1 or using setAlias in application config.
Yuo can use a simple urlHelper (for absolute url)
use yii\helpers\Url;
echo Url::to(['/'], true );

Config codeigniter on remote server (404 not found)

I'm starting to implement a php application on remote server using codeigniter and netbeans. I don't understand why I still have (404 not found) even if I did all the configuration. The connection to the server is OK, I can upload the files. In $config['base_url'], I tried the adress of server, the path to index.html, nothing... with no results.
I actually don't know where is the problem and which file I must change, If someone can help me please to find a solution.
Thank's a lot for yous answers!
It is kinda hard to troubleshoot your question without seeing your configuration. I would say to first double-check that your $config['base_url'] like you mentioned, but set it to whatever the site name/address is. For example, if I am just running something locally on port 8888, it would look like this
$config['base_url'] = 'http://localhost:8888/';
So if your site was something like wwww.example.com it would be
$config['base_url'] = 'http://www.example.com/';
Also double-check your .htaccess file to re-write access if you want to remove 'index.php' from the URL. What web server are you using for your site?
You say "the path to index.html".
This is not how CI works. You shouldn't access views directly. Try accessing them using your Controllers. For example you can have a controller 'Welcome' (which is the standard controller when you download the framework). It can look something like this:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function index()
{
$this->load->view('welcome_message');
}
}
This controller should be located in
application/controllers and it will load a view in application/views. In this case this will load 'application/views/welcome_message.php'. You can define the url for the controller in application/config/routes.php. By default the controller 'Welcome' is called when you just download the framework. Also you talk about the .htaccess file. You can use an htaccess file if you want to remove index.php? from the url. See an answer to this question here: CodeIgniter removing index.php from urlI really recommend to watch some CI basics tutorials before kicking off with the framework. You can get a grasp of how the framework and its folder structure works within a few hours.
**Edit **Perhaps the problem isn't with codeigniter but with your webserver, you can remove your codeingiter installation and add a phpinfo file. This way you can see which php settings your server has (if php is enabled at all). Also note that nginx doesn't work with .htaccess, do if you're using an nginx server you should add a rewrite rule in your config file.
Some hosting providers have Mod_Rewrite disabled by default. use phpinfo() to check if it's enabled.

PHPStorm and CodeIgniter routing issue

I started studying CodeIgniter Web Framework and I am trying to work with PHPStorm 8.0.3 on Kubuntu 14.04. When I unzip CodeIgniter downloaded archive to root Apache folder /var/www/html and go to
localhost/index.php
then it works okay and I see "Welcome to CodeIgniter!" page. Also I
can use
localhost/index.php/welcome/index
and see the same page as it should be.
When I created a new PHP project in PHPStorm and try
localhost:63342/codeignitor/index.php/
then I see welcome page, but if I use
localhost:63342/codeignitor/index.php/welcome/index
then I get 404 page. Also all my own controllers are not available and
cause 404.
I can call my own controller only if I make it default
$route['default_controller'] = 'mycontroller';
I think that this problem occurs because the URL contains name of my project /codeignitor/, but I'm not sure about it. So I need your advice how to set CodeIgniter environment in PHPStorm correctly to solve this problem. Thank you!
Codeigniter uses the URL to determine routing, therefore /codeigniter/index.php/welcome/index and /index.php/welcome/index are not equal paths. I would recommend using one or the other, and adjusting your /index.php and /config/routes.php to accommodate for your desired path.
References:
Codeigniter Subfolder
https://www.codeigniter.com/user_guide/general/urls.html
https://www.codeigniter.com/user_guide/general/routing.html
https://www.codeigniter.com/user_guide/general/environments.html

Routing in codeigniter php

UPDATE
If I browse url like
localhost/myapp/index.php/about_us/index
it works. What is this index.php in url? Do I need to mention it in some config file so that it gets appended and forms correct url in menu/links on site?
Original Question
I have no knowledge of PHP but I got a project which in php (codeigniter) to convert in Ruby on Rails.
I could set up db and application well, when I browse application with base url(without mentioning controller & action) it loads page properly. But as soon as I mention url like
localhost/myapp/home/index
it shows message
The requested URL was not found on this server.
If I change default controller to anything in routes.php that page with index method works fine but not with explicit mentioning controller and action.
I am not sure what is the issue, I don't know how routing works in php :(
Any help will be appreciated.
In CodeIgniter, all requests are directed through the index.php file, which acts like a front controller.
index.php must be present in the URL unless you have created a solution to eliminate it. When using Apache, that is typically done with an .htaccess file. There are hundreds of articles and questions regarding this technique -- certainly you can find something to help you.
In regards to URLs and a config option for defining index.php, CodeIgniter URL helper functions such as site_url() utilize the config setting $config['index_page'] found in application/config/config.php. If you remove index.php from your URLs using an .htaccess solution, you can make this setting blank:
$config['index_page'] = '';
This setting is useful for when you want to rename index.php to something else, as well (not very common).
It seems that you had not configured your web server properly. See this question for details for Apache: routing problem in codeigniter
And here are rules for nginx: http://wiki.nginx.org/Codeigniter

Categories