i want to make iframe in codeigniter which access a php file in my local folder. Like this
<iframe src="assets/kcfinder/browse.php?type=files&dir=/assets/admin/images" frameborder="0" ></iframe>
But the display always redirect it to 404 page. How can i fix it?
Thank you very much.
If you're using CI you are ill-advised to call a php file directly. Create a controller instead and call that instead. Something like:
<?php
require_once dirname(__FILE__) . "/base.php";
class fck extends BaseController {
function __construct() {
parent::__construct();
$this->load->model('myModel');
}
function browse($type,$dir) {
$data['directory'] = $this->myModel->loadDirContent($type,$dir);
$this->load->view("fck/browse", $data);
}
}
?>
Your iframe then looks like this:
<iframe src="/fck/browse/files/assets/admin/images" frameborder="0" ></iframe>
Note that after 'browse' in the URI above you are effectively submitting data. First what is read out as "$type" by the browse function, i.e. "files" then the path itself, i.e. data that contains dashes. This is no longer part of an URL so to speak.
Related
I want to redirect www.myexample.com/back when I call www.myexample/blog/tree without changing the url.
If I put the www.myexample.com/back in browser , it should load www.myexample/blog/tree with keeping the www.myexample.com/back in url bar.
In Laravel I tried
Route::get('/back',function(){
return redirect('/blog/tree');
});
Please assume that the www.myexample/blog/tree is an actual wordpress URL
But it changes the url
Is there any way to achieve this ?
I think you should use the Controller function of www.example.com/blog/free for route www.example.com/back. Two routes use the same function will return the same page. The redirect function will change the url, of course. For example:
Route::get('/blog/free','BlogController#free');
Route::get('/back','BlogController#free');
You can create a view /back and use an iframe to load the blog inside it:
Something like:
Route::get('/back',function(){
return view('back');
});
And then in the view back.blade.php looks like
<html>
<body>
<iframe src="http://www.myexample/blog/tree"></iframe>
</body>
</html>
I am trying to load a view from a controller file. If I reference my class in the view everything is fine, however if I reference a method from that class my css does not load.
Here is a simple example:
Controller file:
<?php
class Example extends CI_Controller
{
public function index ()
{
$this->load->view('myview');
}
}
In the view file this works fine:
<li>EXAMPLE</li>
But, this does not:
<li>EXAMPLE</li>
I also tried to use the site_url() function but the result was the same.
Note: I have loaded the URL helper.
Have you change your .htaccess file to remove index.php in url? then
<li>EXAMPLE</li>
it will not work.
you can try to add
<base href="<?php echo cdn_url()?>" />
into the tag <head></head>
Make sure that you have configured your config to php file properly. Then See take a look and make sure that have you removed index.php from url? if yes then remove index from every url you are targeting.I Hope it will work.
In config.php
$config['base_url'] = 'http://localhost/{your_project_folder}/';
I'm new to Codeigniter and i have a problem in page routing. I have a button placed in my first page
<center>Start</center>
I have a page in my view folder. I want to direct to this page when i click my button. How can i navigate to my page in view folder on button click.
My base url
$config['base_url'] = 'http://localhost/xampp/CodeIgniter/';
Thanks in advance
As you are using codeigniter, you could simply name the function in the contorller that would load the page you want.
<center>Start</center>
or depending on your configurations:
<center>Start</center>
in the controllerName and the functionName:
// Other code ...
$this->load->view('viewFileName');
First load url_helper by
$this->load->helper('url');
Or in your autoload.php set
$autoload['helper'] = ['url'];
Then
Start
Note: Use site_url() instead of base_url(), base_url() suited
for src like
<img src="<?php echo base_url()" /> ....
First you need enable url library
$this->load->helper('url');
then test base_url(); function
Returns your site base URL, as specified in your config file. Example:
echo base_url();
And Calling view page, Suppose your file name is home.php
<?php
class Example extends CI_Controller {
function index()
{
$this->load->view('home');
}
}
?>
Your base url is incorrect
replcae
$config['base_url'] = 'http://localhost/xampp/CodeIgniter/';
to'
$config['base_url'] = 'http://localhost/CodeIgniter/';
then
<center>Start</center>
Read this tutorial for more http://w3code.in/2015/10/codeigniter-installation-beginner-guide/
I want to implement a new module into a site, which is made with CI. I am an absolute newbie with CI and I can not figure out how to create the controller ant the view files. I need the new content to be loaded into an iframe in the current site. So far I have:
controller:
class Module extends Controller {
function __construct() {
parent::Controller();
}
function index() {
$this->common->loadView('module/module');
}
}
view:
<iframe src="/new_module/index.php" width="100%" height="100%" scrolling="NO" frameborder="0" >An iframe capable browser is required to view this web site.</iframe>
route:
$route['module/(:any)'] = "module/$1";
site structure:
resources/
system/
....
new_module/
new_module/index.php
new_module/page1.php
new_module/page2.php
Links should be:
http://mydomain.com/module/page1
http://mydomain.com/module/page2
The link are outside of the iframe and the content should load inside the iframe. So, the iframe src should be changed dynamically.
Obviously, it does not work. Could someone with more experience with CI tell me how it
should be done?
Thank you!
For the frame to change dynamically, just set the target of the link to the iframe:
Page 1
<iframe id="targetFrame" src="" width="100%" height="100%" scrolling="NO" frameborder="0" ></iframe>
As I understand, by default, Codeigniter does not have "modules". That is unless you are using a CMS or somesuch that is built on top of CI in which case you'd need to specify that.
Otherwise, just use controllers correctly to get what you want.
class Pages extends Controller{
public function page($id='')
{
switch $id{
case 1:
$data['pageData']='foo';
break;
...
}
$this->load->view('page_view',$data);
}
}
As title said, I'm trying to figure out how to use javascript and jquery libraries on CI.
Following instruction in the docs, I load the library in my controller:
$this->load->library('javascript');
Then, I define the location of the jQuery file (jquery.min.js) in the config.php:
$config['javascript_location'] = 'http://localhost/ci/assets/js/jquery/');
After that, I open the view file and put in these two lines:
<?php echo $library_src;?>
<?php echo $script_head;?>
First error comes up here: Undefined variable $library_src and $script_head (don't understand where I have to set them)
Anyway, I've commented these lines and continue with jquery lib, by loading it in my controller with:
$this->load->library('jquery');
Next error: Unable to load the requested class: jquery. (it seems that it can't find the lib, what i messed up?)
Checking on system folder it looks all files are in place:
system/libraries/Javascript.php
system/libraries/javascript/Jquery.php
Thanks in advance for your help!
Put the code in the config.php like this:
$config['javascript_location'] = 'js/jquery/jquery.js';
$config['javascript_ajax_img'] = 'images/ajax-loader.gif';
In your controller file (e.g. controllers/sample.php) type this codes:
function __construct()
{
parent::__construct();
$this->load->library('javascript');
}
function index()
{
$data['library_src'] = $this->jquery->script();
$data['script_head'] = $this->jquery->_compile();
$this->load->view('sampleview', $data);
}
In your view file (e.g. views/sampleview.php) type this codes:
<?php echo $library_src;?>
<?php echo $script_head;?>
This works for me. I hope it works for you too. XD
It is important to note that this Driver is marked as experimental so I wouldn't rely on it.
Also, personally I think it's asking for confusion and headaches to try and directly mix server-side portions of your applications with client side portions.
To use javascript in your views, I would just start out by loading them like this...
<script type="text/javascript" src="<?= base_url() ?>path/to/jquery.js"></script>
Because this driver is experimental the documentation isn't quite there yet. But I was able to find a solution.
First, the documentation has an error in it. Unless you change the core Javascript library (not suggested) the reference variable is not $script_head but in fact$script_foot.
Second, once you've finished making your calls, it seems you need to run
$this->javascript->external();
and
$this->javascript->compile();
These functions set the $library_src and $script_foot variables.
To put it all together, in your controller you would have:
class Some_Controller extends CI_Controller {
public function index()
{
$this->javascript->click('#button', "alert('Hello!');");
$this->javascript->external();
$this->javascript->compile();
$this->load->view('index');
}
}
In your view you would have
<html>
<head>
<?php echo $library_src; ?>
<?php echo $script_foot; ?>
Although CI first looks for system folder, you can also try putting your libs in the these folders:
application/libraries/Javascript.php
application/libraries/javascript/Jquery.php
Not sure why you have to load your js file via controller and then echoing it in your view. You can just load ur js file using HTML tags directly in your view. Passing data from controller and echoing it in view is mostly used when your variable's value is dynamic/ needs to be loaded from databases etc.
As we know on the user guide, first, it was an experimental but working. Thr first step is open your config file under application/config/config.php .
Put the following line :
// path to JS directory you want to use, I recommended to put the .js file under 'root app/js/yourfile.js'
$config['javascript_location'] = 'js/yourfile.js';
Second step is open your controller, within constructor method, put the following code :
// Load javascript class
$this->load->library('javascript');
$this->load->library('javascript/jquery'); // if u want to use jquery
Then, still in controller file within index method :
$data['library_src'] = $this->jquery->script(); // Because I refer to use jquery I don't test to use $this->javascript->script().
Then open your view file and put the following code within tag head :
<?php echo $library_src; ?>
That way is working for me, let's try it.
Use:
$this->load->library('javascript/jquery');
instead of:
$this->load->library('jquery');
This will load your jQuery library.
I had the same problem, and found :
<?php $this->load->library('javascript'); ?>
<?php $this->load->library('javascript/jquery'); ?>
on https://ellislab.com/forums/viewthread/181742/#860506
Because jquery is in javascript folder.
Or
$autoload['libraries'] = array('database', 'session', 'javascript', 'javascript/jquery');
In the autoload.php file.
That solved the problem of loading the librairy.
You can try this, it's work to me.
in config.php
$config['javascript_location'] = 'http://localhost/ci/js/jquery.min.js';
in Controller
public function __construct() {
parent::__construct();
$this->load->library('javascript');
$this->load->library('javascript/jquery');
}
public function index(){
$d['library_src'] = $this->jquery->script();
$d['logalert']=$this->jquery->_show('#logalert',1000,"$('#logalert').html('hello world');");
$this->load->view('main',$d);
}
in view (head)
<?php echo $library_src; ?>
in view content (body)
<div class="alert alert-dismissable alert-info" id="logalert">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
</div>
in javascript view
<script type="javascript">
$(document).ready(function(){
<?php echo $logalert; ?>
};
</script>
happy coding :)