Joomla pagination is not working in back end (administrator) - php

I used the same code (below) in both front and backend, but the pagination is not working in the admin side.
====================MODEL=PART===========================
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
class CiieModelOrders extends JModelList
{
public function getItems()
{
// Invoke the parent getItems method to get the main list
$items = parent::getItems();
return $items;
}
protected function getListQuery()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('title');
$query->from('q2b7v_menu');
return $query;
}
}
====================VIEW=PART===========================
defined('_JEXEC') or die;
jimport('joomla.application.component.view');
class CiieViewOrders extends JView {
protected $state;
protected $item;
protected $form;
protected $params;
public function display($tpl = null) {
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$this->items = $items;
$this->pagination = $pagination;
parent::display($tpl);
}
}
==================TEMPLATE=PART=========================
<?php
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
//Load admin language file
$lang = JFactory::getLanguage();
$lang->load('com_ciie', JPATH_ADMINISTRATOR);
?>
<div>
<table>
<?php
foreach($this->items as $item){
echo "<tr><td>".$item->title."</td></tr>";
}
?>
</table>
<?php echo $this->pagination->getListFooter(); ?>
</div>
This works fine in the front end (site side).
Session output-> [orders] => stdClass Object ( [ordercol] => [limitstart] => 0 )
Link html/url (for next button)-> <a title="Next" href="/NewJoomla/index.php/component/ciie/?view=other&start=20" class="pagenav">Next</a>
I put the same code in Admin side (backend), and it shows all the paginatiion buttons and everything. But the buttons don't function at all. They simple take me to the top of the page. When I check the links (for example 'next' button) I see this:
Next
(As you can see href attribute value is empty(#).)
Session output-> [orders] => stdClass Object ( [ordercol] => )
(Here also 'limitstart' value doesn't exist at all.
I tried this in different fresh Joomla installations too but the same problems repeats again.
Is there any thing I missed?

Finally I sorted it out! It was a silly mistake!
In the template, I didn't put the list content inside a <form> tag. getListFooter() function shows the pagination buttons, but when clicked the action is not submitted anywhere. I corrected the code as shown below and it worked.
==========TEMPLATE=PART====================
...
<div>
<form action="<?php echo JRoute::_('index.php?option=com_ciie&view=orders'); ?>" method="post" name="adminForm">
<table>
<?php
foreach($this->items as $item){
echo "<tr><td>".$item->title."</td></tr>";
}
?>
</table>
<?php echo $this->pagination->getListFooter(); ?>
</form>
</div>
Thank you all.

Related

last inserted id/latest inserted id function codeigniter

Codes:
View
<html>
<body>
<?php echo form_open('samplecontroller/sample'); ?>
<input type="text" name="samplename"/>
<input type="submit" value="go"/>
<?php echo form_close(); ?>
</body>
</html>
Controller
<?php
Class samplecontroller extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('Sample_insert');
}
function index()
{
$this->load->view('sample.php');
}
function show($data)
{
$this->load->view('sampleresult',$data);
}
function sample()
{
if($result = $this->Sample_insert->insert_into_sample())
{
$this->show($result);
}
}
}
?>
Model
<?php
Class Sample_insert extends CI_Model
{
function insert_into_sample()
{
$sample = array(
'samplename' => $this->input->post('samplename'),
);
$this->db->insert('sample', $sample);
$latest_id = $this->db->insert_id();
return $latest_id;
}
}
?>
The flow is that, i have 2 views. The other one contains only 1 text input, after which goes to controller then controller passes it on to model then model gets the value within the text input then inserts to my sample table.
The sample table has 2 columns, id(PK,AI) and name
after it inserts, on my model. i added a line, return $latest_id. Then passes goes back to my controller then passes it off to another view that only has
print_r($data);
After all that, it displays an error.
Message: Undefined variable: data
Im not sure where the flow went wrong or if i made a syntax mistake. If someone knows/expert on insert_id(), could you pin point where exactly i am wrong? anyways, ive made my research and been getting results on the web how buggy insert_id is. Im not sure if its true or not but ive been redirected mostly to forums wherein insert_id returns null and some say its a bug. Im hoping it isnt.
As per your comment, You have to do some changes in your controller.
function show($data)
{
$this->load->view('sampleresult',array("data"=>$data));
}
You can get inserted id in view in the name of $data.
For ex:
echo $data;
Edit: As per your comment in answer, For multiple row insert in model, add below code
$id_arr = array();
foreach($sample_data as $sample)
{
$this->db->insert('sample', $sample);
$id_arr[] = $this->db->insert_id();
}
return $id_arr;
Now in your view, you will get ids in $data
foreach($data as $id)
{
echo $id;
}

Zend fetchAll foreach 2 times run dont loop 2nd time;

This is very simple to understand
Image Class
<?php
class Image extends Zend_Db_Table_Abstract {
protected $_name = 'images';
public function getList() {
return $this->fetchAll();
}
}?>
My PHP Code
<?php
require 'config.php';
$imgTable = new Image(); // Create Object
$imgList = $imgTable->getList(); // fetch Data
$template = new Template('portfolio'); // Initialize Template and tell which template to pick
$template->imgList = $imgList; // set template variable
$template->render(); // Generate Template output
?>
I can access template variable inside template using $this
Below code is from inside the template
$xback = 0;
foreach ($this->imgList as $images) {
echo 'imageArray[' . $xback . '] = "' . $images['sef'] . '";';
$xback++;
}
?>
.......
<?php
foreach ($this->imgList as $images) {
?>
<div class="portfolio_item">
<img src="<?php echo PATH_WEB . $images['image_thumb'] ?>" height="146" width="209" />
<div class="title"><?php echo $images['image_title'] ?></div>
<div class="right link">
View Details
</div>
</div>
<?php
}
?>
Above code is working fine, but below some few lines, I have to iterate over the same data again dont output any thing. If I comment the first one, 2nd starts working.
First one is to create the JS array and is in head section,
Second part is in HTML to display images
I hope its a pointer issue, I may have to set the loop current item to start, but I am not understanding it right now .... reset($this->imgList) didnt worked
please help
I think it has something to do with the fetchAll call, try this:
<?php
class Image extends Zend_Db_Table_Abstract {
protected $_name = 'images';
protected $images;
public function getList() {
// Employ lazy loading pattern to load images if they aren't set yet
if (!isset($this->$images)) {
$this->images = $this->fetchAll();
}
return $this->images;
}
}?>

pagination is not working in codeigniter :(

I want to display 2 rows in view page as an output. Again when i click on to go to the next page it will display 2 next rows and so on ( All together I have 8 rows in
table). But when I run the following code it displays all 8 rows in the view-page along with pagination links. I tried whole day to find the actual reason for not
working it but my problem is still unsolved. I searched for the help on internet with related query but it was of no use. Finalyy I am here with my own words to explain
the problem. I've commented almost all the lines in my code. I am loading libraries in autoload for pagination and helper for form and url. I'll really be thankful if
somebody help me out. Thanks in advance.
<?php
class ManageUser extends CI_Controller { // creating class for the controller
function index()
{
if($this->session->userdata('logged_in')) // checking users under session if he is already logged in
{
$this->load->model('admin/user'); // loading model . I am not using Datamapper.
$result = $this->user->view_user(); // getting response from the model and storing it to result
$total_rows = count($result); // counting number of rows countered ( its 8 in in my database )
//echo $total_rows;
if($result)
{
$data['users'] = $result;
$config['base_url'] = "http://192.168.0.102/project/index.php/admin/manageUser"; // this is the address where I am pointing the view page url
$config['total_rows'] = $total_rows; // Total numbers of rows assigned to pagination-config
$config['per_page'] = '2'; // I want to display 2 rows in 1 page
$config['uri_segment'] = '2';
$this->pagination->initialize($config); // initilizing the pagination-config
//$data['pagination'] = $this->pagination->create_links();
//$this->load->vars($data);
$this->load->view('admin/manageUser',$data); // Loading the page
}
//$this->load->view('admin/manageUser',$data);
}
else
{
redirect('admin/login'); // incase of faliured session user will be redirected to the login-page.
}
}
}
?>
Following code is from my model named User
<?php
Class User extends CI_Model // extending the model
{
function __construct()
{
parent::__construct();
}
function view_user() // function which is loaded from controller
{
$query = $this -> db -> get('users'); //query to fetch all the information from the database
return $query->result(); // returning result to the Controller.
}
}
?>
And finally this is the view page I am using to display the content .
<!-- This is the view page -->
<?php if(isset($users)) { ?> <!-- Checking if user is set -->
<?php foreach($users as $user) { ?> <!-- running in a loop to accept all the value from the database and display it row wise -->
<td><?php echo $user -> us_display_name; ?></td> <!-- Displaying name -->
<td><?php echo $user -> us_first_name . " " . $user -> us_last_name; ?></td> <!-- Displaying first name and last name together -->
<td><?php echo $user -> us_email_id; ?></td> <!-- Displaying email-ID -->
<?php } } else { ?>
<tr> <td>No records found!</td>
<?php } ?>
<?php echo $this->pagination->create_links(); ?>
You are getting all the users from the Model. That's not how you do it.
Your controller should be something like this :
<?php
class ManageUser extends CI_Controller { // creating class for the controller
function index($offset)
{
if($this->session->userdata('logged_in')) // checking users under session if he is already logged in
{
$this->load->model('admin/user'); // loading model . I am not using Datamapper.
$perpage = 2;
$result = $this->user->view_user($offset,$perpage); // getting response from the model and storing it to result
$total_rows = $this->db->count_all('users');
if($result)
{
$data['users'] = $result;
$config['base_url'] = "http://192.168.0.102/project/index.php/admin/manageUser"; // this is the address where I am pointing the view page url
$config['total_rows'] = $total_rows; // Total numbers of rows assigned to pagination-config
$config['per_page'] = $perpage; // I want to display 2 rows in 1 page
$config['uri_segment'] = '2';
$this->pagination->initialize($config); // initilizing the pagination-config
//$data['pagination'] = $this->pagination->create_links();
//$this->load->vars($data);
$this->load->view('admin/manageUser',$data); // Loading the page
}
//$this->load->view('admin/manageUser',$data);
}
else
{
redirect('admin/login'); // incase of faliured session user will be redirected to the login-page.
}
}
}
?>
And in the model you need to limit the result
<?php
Class User extends CI_Model // extending the model
{
function __construct()
{
parent::__construct();
}
function view_user($offset,$limit) // function which is loaded from controller
{
$query = $this -> db -> get('users',$perpage,$offset); //You dont fetch all the data from the database
return $query->result(); // returning result to the Controller.
}
}
?>

i need help in applying sfFeed2Plugin

i installed the plugin and cannot find anything that tells me how it works and how to use it.
i have the icon in place and an empty onClick event
in homeSuccess.php:
<input class='submit_img' type="image" src="/images/rainbow/feed-icon-14x14.png" value="Feed" alt="Feed" onClick="gotoFeed(this.value,<?php echo $usr_profile->getId();?>)">
gotoFeed JS in homeSuccess.php:
function gotoFeed(id)
{
console.log("testing");
//must redirect to feeds page??
}
in the actions class:
public function executeFeed(sfWebRequest $request)
{
$profile_id = $this->getUser()->getAttribute('profile_id','zero');
}
can anybody help please?
thanks
You can find the complete tutorial at this link sfFeed2Plugin, just clicking the tab Readme
UPDATE
I'm using this plugin with an action like this in my action class:
public function executeFeedRss(sfWebRequest $request)
{
$feed = new sfRss201Feed();
$feed->setTitle('MySite');
$feed->setLink($this->generateUrl('#homepage'));
$c = new Criteria;
$c->addDescendingOrderByColumn(PostPeer::CREATED_AT);
$c->setLimit(10);
$Posts = PostPeer::doSelect($c);
foreach ($Posts as $post)
{
$item = new sfFeedItem();
$item->setTitle($post->getTitle());
// according to routing rule
$item->setLink($this->generateUrl('#posts', array('id'=>$post->getId())));
$item->setPubdate($post->getCreatedAt('U'));
$item->setUniqueId($post->getSlug());
$item->setDescription($post->getBody());
$feed->addItem($item);
}
$this->feed = $feed;
}
and this code inside the template feedRssSuccess.php:
<?php decorate_with(false) ?>
<?php echo $feed->asXml(ESC_RAW) ?>
Finally simply I have a link to this action in my layout through a template, but of course in a pageSuccess.php is the same.
I hope this can help you.

Function Help -> Organization

I am trying to get the following function to run when the link is clicked and then load the previous page, but I seem to end up with a blank page with no php errors:
View:
<?php if(is_array($get_images)): ?>
<?php foreach($get_images as $image): ?>
<img src ="<?=base_url()?>includes/uploads/gallery/thumbs/<?=$image['thumbname']?>" alt="<?= $image['description']?>"> Delete
<?php endforeach; ?>
<?php endif; ?>
Controller:
function delete($id) {
$id = $this->uri->segment(3);
$this->image_model->deleteImage($id);
$page['get_images'] = $this->image_model->getImages();
$data['cms_pages'] = $this->navigation_model->getCMSPages();
$data['title'] = 'Delete Gallery Image';
$data['content'] = $this->load->view('admin/deleteimage',$page,TRUE);
}
}
Firstly, a destructive thing such as deleting an image should be POST, not GET.
As for the code, something like this should work (assuming that last closing brace means your function is a class method)...
// However you extract params in your framework.
$id = $request->getParam('id');
// Instantiate the class.
$controller = new ImageController;
// Call the method.
$controller->delete($id);

Categories