Welcome Guest, Not a member yet? Register   Sign In
Linking PHP files in a view
#1

[eluser]cz231[/eluser]
Hi codeigniter community!

I'm pretty new to codeigniter and it's ways, so while building an application with it I encountered a problem: How do I link to a PHP file in a view?

I think this is better served with an example:

I have a view with a directory of views/events/cal.php:
Within that file I have a script that references a PHP file:

Code:
<script>
var dp = new dataProcessor("connector/events.php");
<script>

How do I link to that file?

Thanks,

Connor
#2

[eluser]stef25[/eluser]
if i understand you right you need a server path. you can find this out by putting the code below in your events.php file. that will show you the full path which you then pass as the parameter to dataProcessor()

<?php echo realpath(dirname(__FILE__)); ?>
#3

[eluser]cz231[/eluser]
Hm...I don't think that's what I'm looking for. I'm trying to find out how I can directly link to the events.php file, while still using a web address. (http not fileSmile
#4

[eluser]jedd[/eluser]
[quote author="cz231" date="1250640568"]Hm...I don't think that's what I'm looking for. I'm trying to find out how I can directly link to the events.php file, while still using a web address. (http not fileSmile[/quote]

There's several options

Don't do it - instead put it outside the CI directory structure
Have a controller/method that spews out a raw view without doing any processing around it
Modify your .htaccess file to allow access to this path/file

Which way you go depends on why you're trying to do what you're trying to do.
#5

[eluser]cz231[/eluser]
How do you make a directory accessible using htaccess? My htaccess file looks like this right now:

RewriteEngine On
RewriteBase /suite
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#6

[eluser]jedd[/eluser]
Wow .. that's one fat .htaccess. I like mine more - it's got less redundancy (I don't like repeating myself twice).

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|files|assets|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]

The hint is index.php, files, assets, robots.txt - are all things that I'm excluding from being munged by the subsequent rewrite rule. So .. add another one in, and away you go.




Theme © iAndrew 2016 - Forum software by © MyBB