displaying row details in zend framework - zend-framework

I am simply trying to show detail view page from table page
I have set up displaying list of pages via another function like this and works fine
> <a href="< ? php echo
> $ this -> url(array('controller'=>'page','action'=>'detail',
> 'id'=>$page->id));? >"> < ? php echo
> $this->escape($page->title);? ></a>
In my controller i added
public function detailAction()
{
$id = $this->_getParam('id', 0);
$page = new Application_Model_DbTable_Pages();
$this->view->myVar = $page->getPage($id);
}
and in view
> <?php print_r($this->myvar) ?>
This list
I just see blank page, how can i show detail page ?

Try:
<?php print_r($this->myVar) ?>
insted of myvar --> myVar. That is how You called Your variable in the action method.

Related

Get Category Description in my cutom phtml file in magento 2

I am using Magento 2. I want to get category description and image in my custom phtml file.
How can i do that?
If you want to get in current category information in phtml you can use following code.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currentCategory = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category information
echo $currentCategory->getId();
echo $currentCategory->getName();
echo $currentCategory->getDescription();
echo $currentCategory->getImageUrl();
?>
Or do you want to load any specific category then you can use below code.
$categoryId = 3;
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $_objectManager->create('Magento\Catalog\Model\Category')
->load($categoryId);
echo $category->getName();
echo $category->getImageUrl();

How can i redirect to previous page after a form submit in codeigniter

I have a test function in controller which generates a form page.
public function testing()
{
$this->form_validation->set_rules('test', 'TEST', 'required');
if ($this->form_validation->run()) {
redirect($this->agent->referrer());
} else {
$data['title'] = 'Testing';
$data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->load->view('templates/header', $data);
$this->load->view('pages/nonmember/testing', $data);
$this->load->view('templates/footer');
}
}
The code of testing view as below
<div id="message"><?php echo $message; ?></div>
<?php echo form_open(base_url()."testing");?>
<p>
<?php echo form_input('test');?>
</p>
<p><?php echo form_submit('submit', 'Submit');?></p>
<?php echo form_close();?>
If users come from another page lets say About page to testing page i want after submitting form properly they get redirected back to About page. But it is not being possible as referer agent is staying at the testing page, so after submit it is staying there and not redirecting to About page.
All you need is:
redirect($_SERVER['HTTP_REFERER']);
add this line in your controller's testing function
$this->session->set_flashdata('url',$this->agent->referrer());
change this in the function testing
if ($this->form_validation->run()) {
redirect($this->session->flashdata('url'));
} else {
$this->session->set_flashdata('url',$this->agent->referrer());
//load the view
}
...
or you can also submit an hidden field like,
form_hidden('rURL', $this->agent->referrer());
then simply use its value in the controller.
if ($this->form_validation->run()) {
redirect($this->input->post('rURL'));
} else {
...
Not sure if it is the best solution or not , but i found the solution working perfectly.
We need to write the referrer address in a file and to redirect we need to read from that file.
first we need to load the file helper.
$this->load->helper('file');
if ($this->form_validation->run())
{
redirect(read_file('referrer.php'));
}
else
{
$referrer = $this->agent->referrer();
//need to check wrong input submission and page refresh
if ($referrer != "http://localhost/CIpractice2/testing" && !empty($referrer))
{
write_file('referrer.php', $referrer);
}
//show the form
}
Please refer to codeIgniter's file helper documentation

How to filter New WP Query by Custom Field Value?

I am creating new pages for each of my categories in wordpress. The post editor has a custom field that allows the selection of a sector type, this gets applied to the post on update. The custom field key is: sector, for custom field meta value options lets use SectorA, SectorB and SectorC. I am using a custom post type called projects.
I followed the advice at this link http://weblogtoolscollection.com/archives/2008/04/13/how-to-only-retrieve-posts-with-custom-fields/
How can I change the query line in the code below so that it filters the loop by a Sector name, lets use SectorA. I'll then reuse the code on each template page changing the value to SectorB and SectorC on the other pages.
I think this needs changing somehow:
$customPosts->query('showposts=5&sector=sectorA&post_type=projects' );
Currently it echos the sector value and description value successfully but is showing all the posts. So my attempt to limit it to sectorA using sector=sectorA doesn't seem to work?
This code is in functions.php:
function get_custom_field_posts_join($join) {
global $wpdb, $customFields;
return $join . " JOIN $wpdb->postmeta postmeta ON (postmeta.post_id = $wpdb->posts.ID and postmeta.meta_key in ($customFields)) ";
}
function get_custom_field_posts_group($group) {
global $wpdb;
$group .= " $wpdb->posts.ID ";
return $group;
}
And this code is on the Template Page:
<?php /* Begin Custom Field Posts */ ?>
<h2>Custom Posts</h2>
<ul>
<?php
global $customFields;
$customFields = "'sector', 'description'";
$customPosts = new WP_Query();
add_filter('posts_join', 'get_custom_field_posts_join');
add_filter('posts_groupby', 'get_custom_field_posts_group');
$customPosts->query('showposts=5&sector=sectorA&post_type=projects' );//Uses same parameters as query_posts
remove_filter('posts_join', 'get_custom_field_posts_join');
remove_filter('posts_groupby', 'get_custom_field_posts_group');
while ($customPosts->have_posts()) : $customPosts->the_post();
$sector = get_post_custom_values("sector");
$description= get_post_custom_values("description");?>
<li><?php echo $sector[0]; ?></li>
<li><?php echo $description[0]; ?></li><br />
<?php endwhile; ?>
</ul>
<?php /* End Custom Field Posts */ ?>
Thanks for your help
May be this what you want
function get_custom_field_posts_join($join) {
global $wpdb, $customSector;
return $join . " JOIN $wpdb->postmeta postmeta ON (postmeta.post_id = $wpdb->posts.ID and postmeta.meta_key = 'sector' and postmeta.value = '$customSector') ";
}
and modification of page
$customSector='sectorA';//<--- insert this
add_filter('posts_join', 'get_custom_field_posts_join');
Try using this code.
<?php
$sector = get_post_meta($post->ID, "sector", false);
if ($sector[0]=="") { ?>
<!-- If there are no custom fields, show nothing -->
<?php } else { ?>
<div class="sector">
<h3>Title</h3>
<?php foreach($sector as $sector) {
echo '<blockquote><p>'.$sector.'</p></blockquote>';
} ?>
</div>
<?php } ?>

How to use Zend ProgressBar in a Zend MVC application

I've been trying to use the JsPush Zend progress bar in a Zend MVC application, but have not been successful. I've used the JsPush.php example found on github to create a standalone progress bar test application, but this does not use the Zend MVC framework. When I apply the CSS, HTML, JavaScript, and PHP code from the JsPush example program, I see my progress bar appear (the CSS works) but I don't get any results during my socket write process. I've used the JsPush CSS code verbatim in a css file that is linked to my application so I won't repeat that here. Below are exerpts from my MVC application, the controller code:
protected function _sendFile($job)
{
$fp = fopen($job->source_file, "rb");
if($fp == null || $fileData['size'] == 0) {
$this->view->errorMessage = 'Error - file open failed for ' . $job->source_file;
return false;
}
$this->totalXmitSize = $fileSize;
$this->currentXmitSize = 0;
$progressMessage = '';
$adapter = new Zend_ProgressBar_Adapter_JsPush(array
('updateMethodName' => 'Zend_ProgressBar_Update',
'finishMethodName' => 'Zend_ProgressBar_Finish'));
$progressBar = new Zend_ProgressBar($adapter, 0, $this->totalXmitSize);
while(!feof($fp)) {
$blkSize = ($fileSize > 1024) ? 1024 : $fileSize;
$xmitBuf = fread($fp, $blkSize);
if($xmitBuf === false || !strlen($xmitBuf)) {
$this->view->errorMessage = 'Error - file open failed for ' . $job->source_file;
return false;
}
if($this->_writeData($xmitBuf, $blkSize) == false) {
return false;
}
$fileSize -= $blkSize;
$this->currentXmitSize += $blkSize;
$progress = $this->_calculateXmitProgress();
if($progress < 25) {
$progressMessage = 'Just beginning';
} elseif($progress < 50) {
$progressMessage = 'less than half done';
} elseif($progress < 75) {
$progressMessage = 'more than half done';
} else {
$progressMessage = 'almost done';
}
$progressBar->update($this->currentXmitSize, $progressMessage);
if($fileSize <= 0) {
break;
}
}
fclose($fp);
$xmitBuf = '';
$bufLen = 0;
if($this->_readData($xmitBuf, $bufLen) === false) {
return false;
}
$progressBar->finish();
if(strncmp($xmitBuf, MSG_STATUS_OK, strlen(MSG_STATUS_OK)) != 0) {
$this->view->errorMessage = 'Error - invalid response after file transfer complete';
return false;
}
return true;
}
The view code:
<?php
$this->title = "My Title";
$this->headTitle($this->title);
$this->layout()->bodyScripts = 'onload="startProgress();"';
?>
<p class="errors"> <?php echo $this->errorMessage ?> </p >
<?php echo $this->form->setAction($this->url());
?>
<div id="progressbar">
<div class="pg-progressbar">
<div class="pg-progress" id="pg-percent">
<div class="pg-progressstyle"></div>
<div class="pg-invertedtext" id="pg-text-1"></div>
</div>
<div class="pg-text" id="pg-text-2"></div>
</div>
</div>
<div id="progressBar"><div id="progressDone"></div></div>
The layout.phtml code:
function startProgress()
{
var iFrame = document.createElement('iframe');
document.getElementsByTagName('body')[0].appendChild(iFrame);
iFrame.src = 'MyController.php';
}
function Zend_ProgressBar_Update(data)
{
document.getElementById('pg-percent').style.width = data.percent + '%';
document.getElementById('pg-text-1').innerHTML = data.text;
document.getElementById('pg-text-2').innerHTML = data.text;
}
function Zend_ProgressBar_Finish()
{
document.getElementById('pg-percent').style.width = '100%';
document.getElementById('pg-text-1').innerHTML = 'done';
document.getElementById('pg-text-2').innerHTML = 'done';
}
</script>
</head>
<body <?php echo $this->layout()->bodyScripts ?>>
<div>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->layout()->content; ?>
</div>
When this runs I get a ton of JavaScript in the page source, but no progress results:
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":0,"max":3397,"percent":0,"timeTaken":0,"timeRemaining":null,"text":null});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":1024,"max":3397,"percent":30.14424492199,"timeTaken":0,"timeRemaining":0,"text":"less than half done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":2048,"max":3397,"percent":60.28848984398,"timeTaken":0,"timeRemaining":0,"text":"more than half done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":3072,"max":3397,"percent":90.43273476597,"timeTaken":0,"timeRemaining":0,"text":"almost done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":3397,"max":3397,"percent":100,"timeTaken":0,"timeRemaining":0,"text":"almost done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Finish();</script><br />
All of this JavaScript pushes my form out of view. I have spent days on the Zend documentation site and scouring the web to find examples of someone successfully using Zend ProgressBar in a MVC framework application, but can not find any working examples. Thanks in advance for any help.
Well I have been successful in getting a JsPush progress bar to work to some degree, but not 100% correct for my application.
The progressbar works, but the form results end up in the hidden iframe. There is no way to get to the submit buttons on that iframe, so my user has to use the back button to get out of the form.
The only way to get the progress bar to work is to use the target attribute in the form and assign it to the name attribute of the iframe. If I don't use the target attribute, the form scrolls for every call to progressBar->update;. So my form results end up on the parent page several hundred lines scrolled down and the scroll bar never works.
I've tried using the example from the Zend documentation, but it doesn't work. This is my first venture into the Zend framework and it has been very frustrating and disappointing. Not a single response to my original question from 28 days ago.
I had same problem. For me it worked since I did the following steps.
Go to the php.ini and check if the following Data is set in your php.ini.
output_buffering = Off
;output_handler =
zlib.output_compression = Off
;zlib.output_handler =
Then go to class Zend_ProgressBar_Adapter_JsPush and find the Method - which is at the bottom - _outputData. Delete everything in this Method and input
// 1024 padding is required for Safari, while 256 padding is required
// for Internet Explorer. The <br /> is required so Safari actually
// executes the <script />
echo str_pad($data . '', 1024, ' ', STR_PAD_RIGHT) . "\n";
echo(str_repeat(' ',256));
if (ob_get_length()){
#ob_flush();
#flush();
#ob_end_flush();
}
#ob_start();

View Helper in Kohana

I am trying to figure out a way to do the following:
I want to make an action which will be loaded through ajax and also its the internal part of the page when page is reloaded.
I know this in ZEND framework by using View Helper, But don't know how to do in Kohana
I am new to Kohana.
EDIT:
Example of what I am trying to do http://www.espncricinfo.com/west-indies-v-india-2011/engine/current/match/489228.html?CMP=chrome
In above webpage when the whole web page is loaded the live score board is loaded with it. But when u click on "Refresh scoreboard" button only the live score board is replaced through ajax.
I want to create an action say action_scoreboard which will be used to bring scoreboard data. And action_index to load the whole page, but while in the view of action_index i need to call action_scoreboard.
Thanks
Not sure if this is the best way to do this, but this is how I like to handle the situation.
public function action_index($raw = 0) {
$records = Jelly::select('scores')->execute();
if ($raw == 0) {
$view = new View('purdy');
$view->records = $records;
$this->template->content = $view;
} else {
$this->auto_render = FALSE;
$this->request->headers['Content-Type'] = 'text/xml';
$view = new View('raw');
$view->records = $records;
$this->response->body($view->render());
}
}
### THE PURDY VIEW ###
<table>
<?
foreach ($records as $record) {
echo '<tr>';
echo '<td>'.$record->name.'</td>';
echo '<td>'.$record->value.'</td>';
echo '</tr>';
}
?>
</table>
### THE RAW VIEW ###
<?xml version="1.0" encoding="utf-8"?>
<scores>
<?
foreach ($records as $record) {
echo '<score>';
echo '<name>'.$record->name.'</name>';
echo '<value>'.$record->value.'</value>';
echo '</score>';
}
?>
</scores>
I used Kopjax - Pjax jQuery ajax module. Its code is available on gitgub