How require_once in joomla2.5 - joomla

I Have a problem about require_once in joomla.
In this file php:
components\com_test\views\__test_r5\tmpl\default.php
I want to include some file using this code:
require_once (JPATH_ROOT.DS.'/includes/General.php');
but require_once does not works

The path you are trying to include will evaluate to something like: joomla//includes/General.php. Notice the double slashes before "includes".
The constant DS is defined to be a directory separator.
Try:
require_once (JPATH_ROOT.'/includes/General.php');
(without DS)

Try This :
require_once(JPATH_SITE.DS."includes/General.php");
The JPATH_SITE will return your physical path upto : installation folder.
also JURI::root() will return your site url

The best way to do this is to use #Fnatte variant.
Also have a look at the Joomla! constants definitions and adapt where needed.

Related

base url is getting calling an inner folder

When I use echo base_url() in some portions of the application, it works fine.
My base_url() is http://localhost:8080/appname/
But when I do this <?php echo base_url(); ?>data/profile/avatar-5.png
The url appears like http://localhost:8080/appname/admin/data/profile/avatar-5.png where admin is a folder. I guess its because from where it is called from. But yet the base_url() should actually give the right url. Any ideas?
In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php:
$autoload['helper'] = array('url');
Or, manually:
$this->load->helper('url');
Also don't forget to set base_url in application/config/config.php
$config['base_url'] = "http://localhost:8080/appname/';
Then try
<?php echo base_url('data/profile/avatar-5.png'); ?>
If the base path is not working for you, you can try my solution which I usually use
Create an separate path for logo or image
$config['image_path'] = ' http://localhost:8080/appname/admin/data/profile/';
use that in you view controller as
echo $this->config->item('image_path').$imagename;

How do I include file in codeIgniter application, which is outside application folder

I want to include this file
api/app/PHPexcel/phpexcel.php
Into this library
application/library/excel.php
In codeIgniter. Base url in my config file is empty.
pls help.
On your file try include or require
File-name: application > library > Excel.php
<?php
// dirname will let you access out side application folder.
$file = dirname(FCPATH . '/api/app/PHPexcel/phpexcel.php');
// $file = FCPATH . 'api/app/PHPexcel/phpexcel.php';
require_once $file;
class Excel {
public function __construct() {
}
}
Folder Layout
application
api
api > app
system
index.php
Best not to leave your base_url blank will run into some issues later.
Use absolute path. Something like:
'/var/www/html/api/app/PHPexcel/phpexcel.php'
or
'C:\wamp\www\api\app\PHPexcel\phpexcel.php'
Note that you have some predefined constants in CodeIgniter itself:
APPPATH => '/path/to/application/'
FCPATH => '/path/to/directory/where/index/php/file/is/
etc...
Those constants are defined in index.php file.
Commonly used practice is to put (e.g.) PHPexcel directory into
APPPATH . 'libraries'
location so structure could be
-application
--libraries
---PHPexcel
----phpexcel.php
---Excel.php # don't forget have it with ucfirst rule if CI3
or you can put directory in third_party and include it as
APPPATH . 'third_party/PHPexcel/phpexcel.php';
But it is up to you how do you like to arrange files/directories structure of your app.
In application/config/autoload.php file there is variable named $autoload['libraries'] = array();
you should define your library in this array and your library will be loaded automatically.

How to get public directory?

I am a beginner here so pardon me for this question am using return File::put($path , $data); to create a file in public folder on Laravel. I used this piece of code from controller I need to know the value of $path how should it be.
Use public_path()
For reference:
// Path to the project's root folder
echo base_path();
// Path to the 'app' folder
echo app_path();
// Path to the 'public' folder
echo public_path();
// Path to the 'storage' folder
echo storage_path();
// Path to the 'storage/app' folder
echo storage_path('app');
You can use base_path() to get the base of your application - and then just add your public folder to that:
$path = base_path().'/public';
return File::put($path , $data)
Note: Be very careful about allowing people to upload files into your root of public_html. If they upload their own index.php file, they will take over your site.
I know this is a little late, but if someone else comes across this looking, you can now use public_path(); in Laravel 4, it has been added to the helper.php file in the support folder see here.
The best way to retrieve your public folder path from your Laravel config is the function:
$myPublicFolder = public_path();
$savePath = $mypublicPath."enter_path_to_save";
$path = $savePath."filename.ext";
return File::put($path , $data);
There is no need to have all the variables, but this is just for a demonstrative purpose.
Hope this helps,
GRnGC
I think what you are looking for is asset(''); You can use asset('storage'), after creating your symbolic link.
asset('public')
OR
url('public')

How to find Joomla root directory

how to I find out the Joomla root directory to use in files? I tried the following with no luck:
$path = JPATH_COMPONENT;
//Gives component root
$path = JURI::root();
//Gives absolute path, can't be used for some reason (http://www.site.com)
$path = $_SERVER['DOCUMENT_ROOT'];
//Gives public_html folder, but if someone installs joomla in a directory and not in root, it wrecks the whole thing
Is there a way to find the joomla root of the site only? Thanks.
may be this can help you
http://docs.joomla.org/Constants
Let's say you want to include an image from the images folder, you can simply use this:
$image = JUri::root() . 'images/image_name.png';
JUri::root() and both JUri::site() always define the root directory

Codeigniter base_url() in whack?

I was trying to set up a basic log in form with a following code:
<?=form_open(base_url() . 'main/login'); ?>
However after submitting the form the url shows this:
example.com/main/http//example.com/http//example.com/main/login
So I guess in essence for some reason the base-url is printed twice before the controller/method declaration. If I clear the base url value in my config file then the application works normally. I am however curious on what could cause this. For additional information I am working on xampp with a virtualhost and I have mod-rewrite on with a .htaccess file located at the document root.
CodeIgniter automatically adds the base_url to the action of the form when you use the form helper.
For example, you can use:
<?=form_open('main/login'); ?>
which will produce:
http//example.com/main/login
And a correct URL! Pretty simple! :D
More information at:
http://codeigniter.com/user_guide/helpers/form_helper.html
The file config.php under application/config has the setting:
$config['base_url'] = '';
Give it the folder/directory path. For example:
$config['base_url'] = 'http://localhost/ci_test/';
Don't forget to mention the protocol (http://). Alternatively try the site_url() method instead of base_url() for form opening. Skip it if using the form_open() function:
<form action="<?php echo site_url('main/login'); ?>"> ... </form>
Or
<?php form_open('main/login'); ?>
For more help: http://codeigniter.com/user_guide/helpers/url_helper.html
Not sure about the .htaccess file you have used. But this might be the answer codeigniter: why is that when i echo base_url() in an href attribute of an anchor tag, it echoes twice
Try it by parameter:
<?=form_open(base_url('main/login')); ?>
or
<?=form_open site_url('main/login')); ?>
In order to append the prefix also
You can Use
<?php echo form_open(base_url(main/login)); ?>
You have to use "echo" rather than because it not works in some browsers....

Resources