I have two applications in one Code Igniter project.
application
--PW1
--PW2
This is the directory structure. I changed the application_folder in index.php
$application_folder = 'application/PW2';
This works fine. I followed this example.
What I would like to do is access the second application from the first one. How can I do that. First I tried the simple solution:
<a href="<?php echo base_url(); ?>application/PW1">
But access is forbidden this way. How can I do this?
Take a look at the documentation . It states that
Note: Each of your applications will need its own index.php file which calls the desired application. The index.php file can be named anything you want.
So according to the folder structure you have created, it should look something like this
system
application
----PW1
----index.php (with $application_folder = 'application/PW1';)
----PW2
----index.php (with $application_folder = 'application/PW2';)
Related
I designed a site using Wordpress, and have been trying to get a Codeigniter form app integrated with it, with all the corresponding URLs.
I put the CI app in the root folder of the Wordpress site. The folder is named "Chile" (it's a series of forms separated by LATAM countries). I changed the .htaccess file to include /chile where necessary. I also added:
require '../wp-load.php';
to the CI index.php file.
I can now load some of the essential urls in the CI app, but they don't seem to be routed properly.
the base url is set to:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('#/+$#', '', dirname($_SERVER['SCRIPT_NAME'])).'/';
the site is www.dermusikplatz.com. the form is located under www.dermusikplatz.com/chile/applications which i can reach by manually entering that. but when i try to submit the form, the url appears strangely as www.dermusikplatz.comapplications/save. In general, the urls constructed by the controllers and views just don't seem to be set up properly.
I've looked up the documentation regarding routing and have tried creating a $route rule. but i'm not sure what to route from and to what exactly. I've also seen various threads that suggest using MY_URL_helper to change the value of 'site_url' to 'ci_site_url', to avoid any redundancies between the value that Wordpress and CI have for that, but i'm not sure where to even start with that, even after checking out the helper documentation.
I've also tried going in and changing each path value in statements like these from:
$this->load->view('applications/form');
to:
$this->load->view('/chile/applications/form');
but I understand that makes little sense as that directory doesn't exist. I assumed that changing the .htaccess file and the base_url would cover it, but there seems to be much more to it than that.
I'm a little lost here, and not super familiar with Codeigniter.
If anyone can help set me in the right direction at the very least, I would really appreciate it. Thanks.
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
Change that to:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'] . '/Chile/';
It is worth noting that if you are hosting on Linux the 'Chile' must be the exact same case as your folder is called. So, if it is 'Chile', do not call it 'chile'
I have a newsletter 3rd party system. It has been working really well however I have come across an issue which I'm hoping is a really easy fix.
So this is the root structure of my website
FTP SERVER
/index.php
/news.php
/shane/shane_about.php
/mailist/globals.php
/mailist/mailbar.php
/mailist/mailbar8.php
So I have an input box which allows me to register for a newsletter. It works a treat on index.php and news.php however screws up the whole page on shane_about.php because its in a child directory shane.
Now the problem is in the globals.php
<?php
$main_dir = "maillist/";
$website = "http://www.mysite.com/";
$relative_string="index.php?page=mail&";
$absolute_path="/hostingcompanyserver/something/something/something.com/maillist/";
$lang="lang_english.php";
So I changed the variable $main_dir to "../mailist/"
This then worked on the shane/shane_about.php, then index.php and news.php had the same issue (it screwed up).
I'm sure the solution is very basic, any thoughts would be appreciated.
Thanks Chris
Change $main_dir to an absolute path.
If it's the same as $absolute_path you won't have this problem.
$main_dir = "/hostingcompanyserver/something/something/something.com/maillist/";
The problem at the moment is index.php and news.php look inside maillist as defined by $main_dir. shane_about.php looks inside /shane/maillist/.
You then told it to go up a directory to maillist with ..maillist/. This meant shane_about.php was looking in the right place but index.php and news.php weren't.
By using an absolute path all files look in the same place.
I know how to set up routes for the most part but instead of listing out 50 or so different routes for only one thing I want to change is redundant.
I havemy file system setup like this for my codeigniter application.
-application
-controllers
-admin
login.php
register.php
dashboard.php
As of right now when I go to the following site it shows up the way it should.
http://www.mysite.com/admin/(login,register, dashboard)
However I'd like to manipulate the route to appear as the following without having to change the name of the folder in the file structure.
http://www.mysite.com/my-project/(login,register, dashboard)
Is "my-project" a permanent part of your siteurl, for every single page? Then change your base_url() in the config.
Otherwise:
if your base_url is http://www.mysite.com
and you want to go to http://www.mysite.com/my-project/login
then you set the route to be:
$routes['my-project/(:any)'] = 'admin/$1';
or if only for those three:
$routes['my-project/('login'|'register'|'dashboard')] = 'admin/$1';
SHOULD work, although I don't have a handy way to test at the moment
My website structure somewhat looks like below
css/
lib/
js/
index.php
profile.php
products.php
checkout.php
orders.php
invoice.php
I have added a codeigniter folder in there ...
codeigniter/application/
codeigniter/application/controllers/
codeigniter/application/controllers/mycontroller.php
and other files
I can access CodeIgniter stuff by going to mywebsite.com/codeigniter/mycontroller etc fine.
However, I want to get rid of /codeigniter/ part from the URL. So I was wondering if it is possible to create a whitelist of the files which are CodeIgniter specific? For example, if the URL is mywebsite.com/mycontroller then it does CI stuff otherwise it looks for the plain PHP code file. I have only a couple of CI controllers and loads other non-CI files.
Any ideas?
I think you could use .htaccess to rewrite URL's that don't contain .php, css, lib and js. Something like:
RewriteCond %{REQUEST_URI} !^(\.php|css|js|lib)$
RewriteRule (.*) codeigniter/index.php/$1
So:
http://example.com/css/test.css
stays
http://example.com/css/test.css
(as will all requests to css|lib|js. You can append more things here for the rewrite to ignore)
http://example.com/controller/method
becomes
http://example.com/codeigniter/index.php/controller/method
You can test it out here: http://htaccess.madewithlove.be/
More on rewriting: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Short-term Solution
You can start by simply converting the index.php file into a controller and name it whatever you wish:
<?php
class New_default_controller extends CI_Controller {
public function index()
{
// home page stuff here
}
}
Alter the route.php file and set your default controller so that simply visiting your site will trigger the proper controller:
$route['default_controller'] = 'new_default_controller';
Apply the instructions for Removing the index.php file
Now calls to www.mysite.com/profile.php will access the profile.php at your root and calls to www.mysite.com/new_future_page will call your new_future_page controller.
Please let me know if any of this is confusing or you get stuck.
Optimal Solution
I wanted to leave a comment above but this would have been impossible to show as a comment.
You will have to take your PHP files and put them in the controllers folder like this:
codeigniter/application/controllers/profile.php
codeigniter/application/controllers/products.php
codeigniter/application/controllers/checkout.php
codeigniter/application/controllers/orders.php
codeigniter/application/controllers/invoice.php
Please go through and do the Tutorial before continuing any further. Specifically the Static Pages section will help you in achieving your goal.
You will have to convert your current PHP files to follow the flow of CodeIgniter
I want both index.php included, and index.php excluded from my URIs to work smoothly on my site. I need it because of uploadify not working, and it is giving me a HTTP error.
It works if I have changed this
$config['uri_protocol'] = 'AUTO';
to this
$config['uri_protocol'] = 'QUERY_STRING';
, but then whole system is not working properly.
For your assets, first, on config.php set the $config['base_url'] to your website URL.
Then, when linking to assets on which you do NOT want index.php, just use the function base_url
<?php echo base_url("assets/uploadify/uploadify.swf"); ?>
// Generates http://URL/assets/uploadify/uploadify.swf
Follow the link in the comment from Indranil above to remove index.php from your URIs by modifying your .htaccess file.
Here is the address again for reference:
http://codeigniter.com/user_guide/general/urls.html
Keep in mind too that this can vary from host to host in the way that it needs to be formatted, so follow up on that with your hosting service. Most usually have guides that show you how to configure this properly.
I'd also like to know how you're using your links, but I'll go ahead and explain what I think may be happening to you. If you're doing any kind of link/anchor or redirect() using the URL Helper in CodeIgniter, then make sure you're using the right function to execute those actions. Here's what I mean:
The site_url() function/method will always include index.php in your URIs. Here's an example using the site name http://example.com as your website's domain.
<?php echo site_url('home') ?> will turn into http://example.com/index.php/home
While base_url() function/method will always exclude index.php unless you include it. Here's an example using the site name http://example.com as your website's domain.
<?php echo base_url('home') ?> will turn into http://example.com/home
and
<?php echo base_url('index.php/home') ?> will turn into http://example.com/index.php/home
Keep in mind that using these functions/methods are only effective AFTER you have properly modified your .htaccess file.
Here is the link that shows you a more in-depth difference between the site_url() and base_url() functions.
http://codeigniter.com/user_guide/helpers/url_helper.html
I hope this helps!