CodeIgniter's pagination library is not loading in a particular controller of my project, the same piece of code works fine in other controllers of the same project.
Here is the code that loads correctly: (controller name : Purchases)
// load pagination library
$this->load->library('pagination');
//configure pagination
$page_config['base_url'] = base_url('purchases/list_all');
$page_config['total_rows'] = $total_no_of_purs;
$page_config['per_page'] = $no_of_purs_per_page;
$page_config['uri_segment'] = 3;
$page_config['use_page_numbers'] = TRUE;
//initialize pagination
$this->pagination->initialize($page_config);
and Here follows the code that fails to load pagination library (Controller Name: Employee)
//load pagination library
$this->load->library('pagination');
//configure pagination
$page_config['base_url'] = base_url('employee/list_all');
$page_config['total_rows'] = $total_no_of_emps;
$page_config['per_page'] = $no_of_emps_per_page;
$page_config['uri_segment'] = 3;
$page_config['use_page_numbers'] = TRUE;
//initialize pagination
$this->pagination->initialize($page_config);
I want to say that all the variables assigned to the config are valid. The error I am getting for the second piece of code is:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Employee::$pagination
Filename: controllers/employee.php
Line Number: 115
Line 115 is: $this->load->library('pagination');
In both the classes, the constructor was not loaded with the pagination library. Why does one work and the other not?
$this->pagination->create_links(); only shows pagination when your $total_no_of_emps is greater than $no_of_emps_per_page.
After seeing your coding related to pagination, I want to see your whole controller of employee as seems that extends in employee controller is missing and hence they are not able to load pagination class and hence please paste your complete employee controller here.
Thanks,
Shankar
this error because of
$page_config['base_url'] = base_url('employee/list_all');
try this $page_config['base_url'] = base_url()."employee/list_all"; If not
** you need to define base_url(); first
Related
I am trying to develop a website using a templating method I have created different files and would like to run a query and that query would be available on all templates is it possible to do that? Like I would like to give you an example what I am doing here in the controller I have created a variable like this
$data['navigation'] = 'templates/main_menu';
$this->load->view('main');
Okay so now here what I did in the view of main is I included header and footer there and called the navigation file dynamically like this
$this->load->view($navigation);
Okay so now What I am trying to do is want to get an icons stored in database and other settings as well so I placed a query in the header file
<?php $settings = $this->db->get_where('settings', array('id' => 2));\\ This query is just placed above the doctype in the header file and I would like to be called every where ?>
templates/main_menu.php
$settings->row()->header_bg_color
But I am getting an error as Message: Undefined variable: settings and if i place this settings query within the main_menu.php file it works so like what should be the way i mean it does not make sense to call the query again and again if I would be requiring what will be the best way to do and what is tthe use of model would it be used for the queries if it is then if I place this settings query within the model how would I access it is it possible please advise me
Thank you
hi below is code of controller. i have created the common_library.php file in which i have written all common function that I want to use all views.
class Maintenance extends CI_Controller {
function Maintenance() {
parent::__construct();
// file for all common function
include('application/controllers/common/common_library.php');
$this->load->model('maintenance_model');
$this->load->library('session');
$this->load->library('form_validation');
}
function index(){
/*
* # desc : default function that loads the maintenance_view.
*
*
*/
$data['common_query'] = commonQuery() // define this function in common_library file
$data['model_data'] = $this->maintenance_model->projectdetail();
$data['formtitle'] = 'Maintenance List | BMS';
$this->load->view('maintenance_view',$data);
}
}
I need to do the process of loading a view inside my controller which can be done using something like:
$main['menu'] = $this->load->view('myView', NULL, TRUE);
but when executing I receive an error saying
Undefined property: MainController::$load
How can this be fixed, or if you can give me another way to do the work
You can generate view in your controller with:
// get the view object
$view = View::make('myView'));
// get view content as string
$content = $view->render();
// pass the content to another view
$anotherView = View::make('anotherView', array('content' => $content));
You can read more about how to use views in Laravel 4 here: http://laravel.com/docs/4.2/responses#views. I suggest you have a look here as it seems that what you're trying to do is not the standard way of doing stuff in Laravel.
Hi i am writing the following code in the ZipcodeClassHelper.php
public function get_zip_point($table,$zip) {
App::import('Model','Driver_location');
$MyModel = new Driver_location();
$qry = $MyModel->find("all",array('conditions'=>array('zip'=>$zip)));
pr($qry); exit;
}
I got the error message:
Error: Class 'Driver_location' not found
File: E:\xampp\htdocs\2014\cab-zone\cabs\app\View\Helper\ZipcodeClassHelper.php
Line: 25
Loading a Model in CakePHP when not inside a Controller can be done like this:
$ModelName = ClassRegistry::init('ModelName');
Then query the model:
$result = $ModelName->find('all');
That's violating the MVC pattern, you don't fetch data in the view. Your model is not well named either, it doesn't follow the convention, it should be DriverLocation.
Set your data from the controller to the view:
$this->set('whatever', $this->Model->find('...'));
Do the blog tutorial to get an idea of how Cake work with it's conventions and MVC.
I have a little trouble with naming convention in CakePHP 1.3. I've element called storeItem.ctp, when I'm trying to call it from another view - it works perfect, but when I'm trying to use it as view for action($this->viewPath = 'elements'; and then $this->render(null, 'ajax', '/canvas/storeItem');) I'm getting the error: Error: Confirm you have created the file: ***views/elements/canvas/store_item.ctp.
How can I fix it without renaming element?
An explanation why your code does not work as expected is written in the second paragraph from the bottom in the cookbook. You should try it this way:
$this->layout = 'ajax';
$this->render('/elements/canvas/storeItem');
In the Agile Toolkit Tutorial (Jobeet), I setup the quick data model (Page 3) and it looks nice with the CRUD test page. I tried to change a line of code in the test.php file. The problem is when I added the paginator, line of code, the data in the grid disappeared. Is this a limitation to the paginator class? Is there a quick way to get this custom grid paginated? Thanks.
Original Code displays method not defined error when adding addPaginator as shown below:
$this->add('CRUD')->setModel('Category');
//$this->add('CRUD')->setModel('Job');
$jobCRUD=$this->add('CRUD');
$jobCRUD->setModel('Job');
$jobCRUD->addPaginator(3); //This line causes an method not defined error
Modified code using setSource doesn't display an error but displays an empty grid:
class page_test extends Page {
function init(){
parent::init();
//$this->add('CRUD')->setModel('Category'); //Not needed for my example
$grid=$this->add('Grid');
//$grid->setModel('Job'); //Removed this to show custom columns
$grid->addColumn('id');
$grid->addColumn('type');
$grid->addColumn('position');
$grid->setSource('job');
$grid->addPaginator(3); //Added this to paginate the results (doesn't work & removes data)
}
}
Solution:
$this->add('CRUD')->setModel('Category');
//$this->add('CRUD')->setModel('Job');
$jobCRUD=$this->add('CRUD');
$jobCRUD->setModel('Job');
$jobCRUD->grid->addPaginator(3); // This fixed the paginator
Jobeet is for Agile Toolkit 4.1 and uses "setSource" which is obsolete.
I think if you replace setSource with setModel it should be OK.