I'm trying to call my index.php on my cPanel, however since my hosting service only allows up to 1 sublevel of directory, I have to bring up my index.php.
I'm using Yii framework, and since it's my first application. I dont know how to link it. I also just continued the application from another developer, it's making me confused on how to change or place my index.php
Is it possible to create an index.php to call another index.php, since the current index.php, still has to run the yii framework? I dont want to change the directory paths since there's just too many paths to change.
UPDATE:
Found out I was inputting the wrong path, I've got it to show the page, but now it does not load any of the images/css. What's seems to be the problem now?
I might be asking a dumb question, but have you tried a PHP Include? This won't affect paths or anything, but the code from the included index.php will be used in the first page...
<?PHP
include_once('directory/index2.php');
?>
Related
I am having an issue where I have Laravel installed on the main ./public_html folder and I need to create a side project that has nothing to do with Laravel, actually it's wordpress
So I placed the new project files in ./public_html/ahmal and edited the file in ./public_html/routes/web.php to ignore this directory and redirect to it as it is.
Like so
Route::redirect('/ahmal', '/ahmal/');
But when I go to http://lakatat.net/ahmal/ it says: lakatat.net redirected you too many times.
It is redirecting back and forth between http://lakatat.net/ahmal/ and http://lakatat.net/public/ahmal/
What am I doing wrong here?
I'll appreciate every answer or hint here because I've been stuck for too long on this problem.
So this is the annoying kind of problem where something works perfectly on your local project, but everything breaks once deployed in production.
In this case, i can access all the pages generated by a regular codeigniter controller (situated in application/controllers). However, once i try accessing a HMVC module, i just get a codeigniter 404 error.
Situation still ok for regular controllers:
So for instance, if i have a regular controller C1 situated in application/controllers/C1.php, which contains the function page(), i can access www.mysite.com/C1/page without an issue.
Problem for accessing HMVC controllers:
However, if i want to access the controller C2 situated in application/modules/C2/controllers/C2.php, through the url www.mysite.com/C2/page, i'll get a 404 error.
And problem accessing regular controller through ajax:
A second issue appears when performing an ajax call, using a path which references a regular CI controller. The path used in the ajax call doesn't seem to be recognized, and i receive a 500 error. However, when calling the same path directly in the URL bar, the correct function seems to be executed. I had solved a similar issue before by applying the solution found in Codeigniter base_url() not working properly for ajax. However, i have not yet identified if this is the same issue.
It feels like a loader issue, but i'm no expert!
Even if it was a loader issue, why would it work on local and not on production?
Have you ever encountered something like this? Do you have an idea on how to tackle this issue?
**Edit 3: ** I removed the 2 previous edits because they are now irrelevant.
After activating the debug mode, and adding some logs, i finally found what i think to be the answer.
Long story short, my local codeigniter version runs on windows, and for some reason, when trying to reach a controller, the case is ignored. So File.php and file.php are considered the same.
My production server however runs linux, so it doesn't consider that 2 different file names refer to the same file. So i ask for file.php, and the server answer "there's no such file", because the file i actually want is File.php.
I need to turn in. I'll propose a proper answer tomorrow after running some more checks.
Thanks,
Loïc.
So the issue was not related to regular controllers versus HMVC controllers. Basically what happens is that my local dev environment is Windows, and for some reason, windows decides that the case doesn't matter when naming a file.
So file.php would be seen as the same name as File.php (notice that the first is lowercase and the second uppercase).
In my code, i was trying to get file.php (lowercase), while the actual file was named File.php and it worked, on windows.
However, in civilized operating systems File.php and file.php are considered 2 different names, and that's why suddenly things where not working in production, even though the code was the same. The controller files just could not be found.
I changed the names of my controller files (put them in lowercase) and things are working fine now.
Thanks everyone for your suggestions.
Loïc.
With HMVC routes need to be like
$route['something'] = "module/controller/function";
$route['something/(:any)'] = "module/controller/function/$1";
Make sure like that also when use controllers intead of welcome.php make sure controller filename like Welcome.php
When using routes if have not remove index.php from controller then url would be
With http://localhost/project/index.php/something
Without http://localhost/project/something
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
I've recently implemented the following code to autoload classes in my php code:
function my_autoloader($class) {
include 'classes/class_' . $class . '.php';
}
spl_autoload_register('my_autoloader');
The code is contained in file that gets included at the top of all files that need to generate a web page. So then I set about removing the require_once calls from my code. Here's an example:
require_once('classes/class_web_page.php');
As you'll probably gather from the above, the various pages on my site (it's an online community so there's a forum, gallery, etc) all use the web_page class to generate page headings, menus, etc. The various pieces of code create a web_page object, set various parameters to determine what menu options etc are needed, give the page some content, and generate the html.
All seemed well until I made a change to the class_web_page.php file. The change was immediately apparent on most of the site... except for the home page.
I refreshed my browser, switched if off an on again :-) tried calling http://www.terragenesis.co.uk/index.php rather than just http://www.terragenesis.co.uk/, and even stopped and restarted apache on the server. Despite all this the changes didn't show on the home page. In the end I put the require_once line back into index.php... and presto hey: the changes I'd made in class_web_page.php appeared on the home page.
So it looks to me like the autoloader was loading a cached copy of class_web_page.php and nothing, not even restarting Apache, was going to persuade it to get the new version. Why it should do this for the home page and not the other pages... I have no idea.
Has anybody else experienced this? Have I done something wrong with the autoloader code? How can I fix it... or am I going to have to put all the require_once statements back in place? :-(
My server has PHP version 5.1.6
I found the answer to this... and as usual with "bugs" that elude me for days, it turns out that I did something incredibly stupid:
It turns out that at some point in the past I accidentally uploaded a copy of class_web_page.php into the site home directory rather than the classes subdirectory. So it existed twice.
So, it would appear that despite my autoloader telling php to look in the classes subdirectory, it will look first in the same directory as the main script (index.php in the case of my site's home page). All of the other site page scripts are in subdirectories (forum, gallery, etc) so they were "correctly" using the /classes/class_web_page.php
I've now deleted the copy of class_web_page.php that was living in the home directory... and everything works as it should.
Are you sure that this file is actually loaded (or a cached version of it)?
I have installed zend framework on my local machine. I have configured a vhost in httpd.conf and have added a line in my hosts file (127.0.0.1 mysite). I am running windows 7. Everything works perfect. The problem is when i upload on a hosting server the paths get mixed up.
I am uploading on a remote dir called zf-framework. To access the index page i need to type this url: http://mysite/zf-framework/public. It displays the index page but when i press any links on the page they get mixed up and end up being something like http://mysite/controller/action when in fact it should be http://mysite/zf-framework/public/controller/action. I have found a work-around for this situation...to use echo $this->baseUrl(link) for any links i have in the layout.phtml. The problem is more serious when it comes to submitting forms. I can't use baseUrl there....or i don't know how to use it. Is there a way to write some general config stuff so that this could be automatically resolved by the framework. Let's say to write something in index.php or bootstrap.php that will fix the paths automatically?
If you're using Zend_Application, then add the following to your configs/application.ini file.
resources.frontController.baseUrl = "/your-path-here"
If you're not using Zend_Application, then do this in your bootstrap, or index.php file.
$front = Zend_Controller_Front::getInstance();
$front->setBaseUrl('/your-path-here');
You won't have to use $this->baseUrl() when submitting a form to the same action and controller (just leave out the action attribute in the form tag), or when using the Redirector action helper. However, links in your view scripts will require you to $this->baseUrl('/url-without-base'), which doesn't seem too bad to me.
I am not 100% on this, but if you specify the route in your routes.ini as zf-framework/public/Controller/Action etc this should fix your issue.
I would see this as a bandaid, but I am not 100% sure on how to properly fix your issue other then you modifying the vhosts file on the remote server to set a document root to the public folder. If that is not an option, well the above should work, but know that all of your files are potentially accessible from everyone (at least your folder structure). I am not sure what harm this can do (if any) other then if your database schema is in the /data directory.
It is better to try and get the public set as the web root, if possible.