Passing $data variable to iframe from controller in CodeIgniter - javascript

I want to display a page in iframe. This page contains email contents since I am building an inbuilt email system. But the CSS of the email contents are overriding my CSS styles. Now this page gets some data from $data variable which I Pass through controller.
To avoid getting my CSS style issues I am thinking of displaying that page in an iframe. (If anybody has any other solutions, welcome).
inboxdetailspage.php --> View which displays email contents
mailactions.php --> controller which passes $data to inboxdetailspage.php
This is the function that does it.
function viewInboxDetails(){
$mailId = $this->uri->segment('4');
$data['emailInfo'] = $this->fetchParticularEmailInfo($mailId);
$data['titleText'] = 'Email Information';
$this->load->view('admin/inboxdetailspage',$data);
}
I am absolutely blank on how to achieve this feature

Passing data to the IFRAME from the same controller is not possible.
IFRAMEs' are just basically another URL display on a particular page. Hence all you can do is can pass the data via URL and thats it!
How this can be achieved this is create another (say) link for displaying the mail content by taking the ID from the URL and display that URL in iFrame. For example,
Controller:
public function all_mails()
{
$data['mails'] = $this->xyz_model->get_mails();
$this->load->view('all_mails.php', $data);
}
public function mail_content($mail_id)
{
$data['mail'] = $this->xyz_model->get_mail_content($mail_id);
$this->load->view('mail_content.php', $data);
}
View:
all_mails.php
<?php foreach($mails as $mail) { ?>
<table>
<tr>
<td><?php echo $mail->from; ?></td>
<td><?php echo $mail->subject; ?></td>
<!-- Your email content -->
<td>
<iframe src="/xyz/mail_content/<?php echo $mail->id; ?>"></iframe>
</td>
</tr>
</table>
<?php } ?>
mail_content.php
<!-- Your CSS here -->
<link href="/static/home/css/bootstrap.min.css" rel="stylesheet">
<div>
<?php echo $mail->content; ?>
</div>

First pass $data to your view and from there call another controller which can render your whole iframe from it with its own view.

Create an iframe in the view linking to another function in controller(a new page). In this page display only email contents according to the email.

Related

Load search result php url in div on same page

I have search results and am displaying them in div on left of page. When user clicks on the a particular result (which is a link), it needs to open on the right of the page, without refreshing the page or moving to a new page. How does one do this?
//get rows
$query = $db->query("SELECT * FROM posts ORDER BY id DESC LIMIT $limit");
if($query->num_rows > 0){ ?>
<div class="post_list">
<?php
while($row = $query->fetch_assoc()){
$postID = $row['id'];
?>
<div class="list_item"><h2><?php echo $row["title"] ?></h2></div>
<?php } ?>
</div>
<?php echo $pagination->createLinks(); ?>
<?php } ?>
</div>
</div>
</body>
</html>
You are going to have an onclick listeners on each <a> which will take your file/file.php?id= as input to an ajax call to fetch the contents at file/file.php?id=.
I am not sure how familiar you are with Javascript, if you know it very well then you'll undersntand what I said above, if you don't then please find documentation about AJAX some ajax documentation
You might also want to find documentation on stuff like innerHTML dom manipulation

PHP redirect URL

I have successfully directed my users to a page that contains their information from a table. Using this code:
<?php foreach ($customers as $row) : ?>
<td onclick="window.location='view_customer.php?customer_id=<?php echo $row['id'] ?>&operation=edit';">
</td>
<?php endforeach; ?>
Now they are on view_cutomer.php. The next step would be to redirect the users to another page that also contains their information (the same information). Using a button. The next page is paint.php. I've tried this code, but it does not seem to work. Btw this next page no longer has a table.
<button onclick="window.location='paint.php?customer_id=<?php echo $row['id'] ?>&operation=edit';" class="rbutton">Paint</button>
How do i redirect users to a specific page using their ID?
on the 2nd page the id you want is in the get array (from the url)
<button onclick="window.location='paint.php?customer_id=<?php echo $_GET['customer_id'] ?>&operation=edit';" class="rbutton">Paint</button>

How can I add advertisement script inside yii framework loop?

I am trying to add an horizontal ad in between the content. An example article of my website is: http://articlefirm.com/biography/penny-taylor-age-net-worth-biography-twitter.html. I would like the ad to come somewhere inside the content.
The website is on YII framework. Here's the content code:
<?php echo $page->detail; ?>
Please let me know how could I add script inside the above given code.
you can change your main.php layout and add the code for show the ads as you like this way
if you need pass some php vars to the main.php layout
a simple way is add property to your controller
class YourController extends CController {
public $myParam;
then assign in your action the values you need for params
eg:
$this->myParam ='my_adv';
and then in your layout you can simple
<?php echo $this->myParam; ?>
otherwise if you don't need pass params form controller/action
you can simply change you views/layouts/main.php
adding the conde you need
<?php
echo 'here i cand add the adv i need before the view content';
?>
<?php echo $content; ?>

target iframe from different page in php or javascript

I am creating a template demo bar, where people can view my created web themes. User will click preview button on one page and will be able to see theme in iframe in another page.
Below is the code for link page
<html>
<head></head>
<body>
preview
</body>
</html>
and then on demo page I get the iframe
<iframe src="<?php echo $_GET['theme']; ?>" style="width:100vw; height:100vh;"></iframe>
This works ok, but my problem is in returning url which displays the URL:
http://site/demobar/?theme=http://www.template.com
I want template name instead of template address in URL
http://site/demobar/?theme=themeName
How can I achieve this!!, is there any other alternative with javascript!
First of all, set up an array with possible themes, and pick the appropriate one based on the theme parameter...
<?php
$themes = array(
"theme" => "http://www.theme.com/",
"othertheme" => "http://www.some-other-theme.com/",
);
$themeAddress = $themes[$_GET['theme']];
?>
Next, generate the iframe with reference to the url...
<iframe src="<?php echo $themeAddress; ?>" style="width:100vw; height:100vh;"></iframe>
Then call the url with the appropriate theme name:
http://site/demobar/?theme=othertheme

Updating session variable using onclick in php

I am trying to update the $_SESSION['state'] whenever the user clicks on the anchor tag by firing the onclick event. The variable $state_names_array as all the names of the states of a specific country. But problem is that no matter whichever of the anchor tag I click on, the $_SESSION['state'] is always getting updated by the last element of the $state_names_array.
<?php
foreach($state_names_array as $value){
$temp = '<?php $_SESSION["state"]=$value;?>';
?>
<?php echo $value ?><br>
<?php
}
?>
I will not code whole code, I will just show you an example, how to do it:
<?php
foreach ($state_names_array as $value) {
echo ''.$value.'<br>';
}
?>
Then you will have javascript function change_value:
here you will send ajax call to some PHP file, where you will process $_SESSION["state"]=$value;
Also you didnt say, what you want after anchor is clicked, because you will be able to access new $_SESSION["state"] only after refreshing your site...
Also maybe you just want to redirect to index.php, after clicking on some anchor, and that will be enough for you, then just use value as $_GET parameter, f.e.:
<?php
foreach ($state_names_array as $value) {
echo ''.$value.'<br>';
}
?>
and add to you index.php file this lines:
if (isset($_GET['new_value'])) {
$_SESSION["state"] = $_GET['new_value'];
}

Categories

Resources