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);
}
}
Related
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 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.
I have a client-side html and javascript application that uses a REST API, that returns JSON. Right now I have the main page when you login, store profile information in a javascript object. Then all other pages in the system are displayed in an iFrame, so that they can access the JSON data in the parent page, without making another ajax call.
I need to move the appliation to Zend Framework, due to future requirements, and I'm not sure how to render a single view, that contains an iframe, and then load all other views into it, instead of instantiating a new layout template and just loading the view.
I know enough about Zend Framework to get started, so I'm not looking for basic Zend Framework help, just a crazy use case, why an iframe...I don't know, client requirements.
Thanks in advance :)
Set your default layout to be the one used in iframes (ie, minimal decoration)
; application.ini
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.layout = "iframe"
; refers to application/layouts/scripts/iframe.phtml
In your main page controller, set the layout to be the full page version
public function indexAction() {
$this->_helper->layout->setLayout('full');
// refers to application/layouts/scripts/full.phtml
}
In your full page layout, create your iframe and name it
<iframe src="" name="content" height="100" width="200">You need a Frames Capable browser to view this content.</iframe>
In your main page view, direct links to open in the iframe
<a href="<?php echo $this->url(array(
'action' => 'some-action'
)) ?>" target="content">Click me</a>
The hardest part I'm having with learning Codeigniter is the URI and URL 'theory' if you will.
I followed the original tutorial concerning static pages, and now the code seems to mess EVERY single link up except the main nav bar, requiring me to constantly add routing parameters. I figure I must be doing something wrong.
In my controller, I currently have this code, based off the tutorial:
public function view($page = 'home') {}
My folder structure is:
+ applications
+ views
- welcome.php
+ main
+ css
+ js
- home.php
- about.php
- etc.php
I should point out that the welcome.php page is for the login page. On that page, a link will direct you to home.php (main/home/)
My routing code looks like this:
$route['default_controller'] = 'welcome';
$route['main/(:any)'] = 'main/view/$1';
$route['main/home/home'] = 'main/view/$1';
$route['404_override'] = '';
As you can see, I already had to put a bandaid on it with the <code>$route['main/home/home'] = 'main/view/$1';</code> portion, due to the fact that clicking on "home" while already on the home page would result in linking to main/home/home/ displaying my nav bar, and creating a brand new set of missing links labeled, main/home/about/
In short, I am now trying to reference a .js file and a .css file, but even though the links correctly point to /main/css/style.css it does not recognize it.
Here is my view code for the header (where i load my .css and .js)
<html>
<head>
<title><?php echo $title ?> - TownBuilder - Prototype</title>
<link href="css/structure.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<header>
<ul>
<li> <?php echo $username ?></li>
<li>Account</li>
</ul>
</header>
Any advice on how to set up routing so that it works correctly?
IMHO they need to remove the route's piece from the codeigniter tutorial because it's not necessary, and it screws everyone up.
Here's the gist of how things work. First comment out all of your routes.
Controller:
Class FirstController extends CI_Controller {
public function home() {
// do stuff
$this->load->view('home');
}
}
Make sure you have a view called home.php in your view folder.
Then the url should be <base_url>/controller/method, so in this case it would be <base_url>/FirstController/home
I think you should add the css/js file on the root directory(outsite of the application folder crete a folder called css) as CI has .htaccess files that deny all access to the application folder. You can only include those files from within your scripts.
I want the view script of one of my controller actions to be rendered inside an iframe in my zend framework application. how it is possible?
Have a separate action (maybe controller too ...) for the view you want to render inside the iframe ( you'll probably want to play in this action with $this->_helper->layout()->disableLayout(); or maybe change the layout ... depends on what you're trying to achieve ) , then in you're view you want to show the iframe do
<iframe src="you're iframe action uri">
<p>Your browser does not support iframes.</p>
</iframe>
same as it is in the browser,
set the iframe src to /controllers/view/,
Think if an iframe as a browser in the page with advanced JS controls.
Set the proper Doctype supporting iframes
Then,
In your view:
<iframe src="<?= $this->url(array(
'module'=>'yourmodule',
'controller'=>'yourcontroller',
'action'=>'youraction'),
'default', true); ?> ">
<?= $this->render('/path/to/your/view/youraction.phtml'); ?>
</iframe>