Problems trying to use the Kohana pagination module - php

I have downloaded the Kohana Pagination module from Git and have been having some issues trying to use it.
I moved it into the modules folder and have updated my bootstrap to include the module...
'pagination' => MODPATH.'kohana-pagination',
I have the following code that loads some messages from a simple table with pagination...
public function action_index()
{
$content = View::factory('welcome')
->bind('messages', $messages)
->bind('pager_links', $pager_links);
$message = new Model_Message;
$message_count = $message->count_all();
$pagination = Pagination::factory(array(
'total_items' => $message_count,
'items_per_page' => 3,
));
$pager_links = $pagination->render();
$messages = $message->get_all($pagination->items_per_page, $pagination->offset);
$this->template->content = $content;
}
When I run load this in my browser, I get the following error message...
ErrorException [ Fatal Error ]: 1Call to undefined method Kohana::config()
MODPATH\kohana-pagination\classes\kohana\pagination.php [ 87 ]
82 * #return array config settings
83 */
84 public function config_group($group = 'default')
85 {
86 // Load the pagination config file
87 $config_file = Kohana::config('pagination');
88
89 // Initialize the $config array
90 $config['group'] = (string) $group;
91
92 // Recursively load requested config groups
{PHP internal call} ยป Kohana_Core::shutdown_handler()
If I remove the code relating to the pagination, the page loads the data fine from the database. Any pointers here would be great.
Update
Found this link: https://github.com/kloopko/kohana-pagination, on the back of Ikke, so cheers for the help folks.
Appears that the previously bundled pagination module has been removed, found the kohana-pagination module which has been updated to cater for 3.2.
Hope that helps someone else just starting out. :)

The issue is just the config system has changed for version 3.2. Most modules can be fixed by simply updating
$config_file = Kohana::config('pagination');
to
$config_file = Kohana::$config->load('pagination');

Let me update you the steps to resolve with Kohana paging.
Go to modules/pagination/classes/kohana/pagination.php
Change the
$config_file = Kohana::config('pagination');
to
$config_file = Kohana::$config->load('pagination');
in the same page at the line 199
change this line to
return URL::site(Request::current()->uri).URL::query(array($this->config['current_page']['key'] => $page));
to
return URL::site(Request::current()->uri()).URL::query(array($this->config['current_page']['key'] => $page));
Add uri braces.
This resolved my issue. thank you.

Related

Create function using external php library | shipping

I use Inpost ShipX PHP SDK php library one courier company to post/create shipping using API.
With this code I can get shipping label and save, this working correct:
$shipmentData = json_decode($response->getBody()->__toString(), true);
while ($shipmentData['status'] !== 'confirmed') {
sleep(1);
$response = $api->shipments()->get($shipmentData['id']);
$shipmentData = json_decode($response->getBody()->__toString(), true);
}
$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
'format' => 'Pdf',
'type' => 'A6',
]);
file_put_contents('var/labels/paczkomaty_label.pdf', $labelResponse->getBody()->__toString());
Now I try also get tracking number for created shipping.
I try add to above code:
$trackingResponse = $api->shipments()->tracking()->get($shipmentData['id']);
var_dump($trackingResponse);
But after post I get:
An uncaught Exception was encountered
Type: InvalidArgumentException
Message: tracking resource not found
Filename: /vendor/imper86/php-inpost-api/src/Resource/AbstractResource.php
Line Number: 66
Can anyone check this library and help me build the function correctly or give me a hint how i can check the resource to build the right function?
Code for __call inside /vendor/imper86/php-inpost-api/src/Resource/AbstractResource.php#66:
$className = $this->reflection->getName() . '\\' . ucfirst($name);
In your case it would be Shipments\\Tracking, but there is no such class.
Try doing
$api->tracking()->shippingHistory()->get($shipmentData['id']);
Basically what you see inside src/Resouce dir you can call as method.
I have just performed static analysis of code/structure, may be wrong

Laravel 4.2 -> Pass a variable containing array to Theme partial or layouts

public function about(){
$tempPageID = Input::get('page_id');
$pageLayout = DB::table('tbl_page')->where('id',$tempPageID)->first();
$data = array(
'page' => $pageLayout
);
$layout = $pageLayout->page_layout;
$theme = Theme::uses('homepage')->layout('default',$data);
return $theme->of('layouts/'.$layout,$data)->render();
}
This my code in my HomeController that calls the page about. the thing is the first division of my page is only included in the layout 'default.blade.php' which is {{ Theme::partial('bannerForm') }}
I'm trying to make the content of the whole page dynamic but cant do it because I cant pass the $data to the bannerForm.blade.php the error is Undefined variable: page .
Does anyone encountered this problem? What can I do to make this work? My second plan is to put the whole bannerForm code in the layout 'default.blade.php' to make it simple but still the same error. Unlike the last line of code which works fine.

Wordpress Plugin in error for user Pro

Hey can anyone explain to me why I get this error when I try to save the registration form.
Fatal error: Cannot unset string offsets in /home/wolf/public_html/wp-content/plugins/userpro/admin/admin-functions.php on line 252
Here is the line in question for the php.
/** List all groups **/
function userpro_admin_list_groups(){
global $userpro;
$output = null;
$groups = $userpro->groups;
unset($groups['register']);
unset($groups['edit']);
unset($groups['view']);
unset($groups['login']);
unset($groups['social']);
$array = array(
'register' => __('Registration Fields','userpro'),
'edit' => __('Edit Profile Fields','userpro'),
'login' => __('Login Fields','userpro'),
'social' => __('Social Fields','userpro')
);
IF anyone can shed some liht on this that would be great as far as i see theres nothing written wrong, and even the plugin maker is scrating his head on this....
the config for the php is 5.4
And the Apache is 2.4
Mysql is running 5.6

Cannot declare phptemplate_settings() - Drupal error when trying to configure template

There are two templates, whitejazz and a modified whitejazz (forumwhitejazz) - both are enabled.
I'm trying to configure the modified whitejazz, and I am getting this error - what does it mean?
Should I post anything else to help deduce this? I'm utterly stumped - my googling of this issue has not given me any solid leads.
This is in Drupal 6.25
Fatal error: Cannot redeclare phptemplate_settings() (previously declared in /home/domain/public_html/drupal-6.25/sites/all/themes/whitejazz/theme-settings.php:3) in /home/domain/public_html/drupal-6.25/sites/all/themes/forumwhitejazz/theme-settings.php on line 135
The problem is that function phptemplate_settings() was defined twice. This goes to fatal php error.
What I suggest to do is:
Create file theme-setting.php in root folder of forumwhitejazz template
There define function as in example and put there code settings.
Example:
function forumwhitejazz_settings($saved_settings) {
$form = array();
$form['forumwhitejazz_example'] = array(
'#type' => 'checkbox',
'#title' => t('Use this sample setting'),
'#default_value' => $saved_settings['forumwhitejazz_example'],
'#description' => t("This option doesn't do anything; it's just an example."),
);
return $form;
}

What is a minimal, complete example of pagination in Kohana 3.2?

I found much information about pagination in Kohana 3.2 but most of it is scattered across forum comments and blog posts with no single complete source to refer to.
(note: I intended to self answer this question)
This is what worked for me:
Download the pagination module from https://github.com/kloopko/kohana-pagination (pagination was removed from Kohana 3.2, so this is an adapted module).
Install the module in modules/pagination.
Add the module in bootstrap.php:
Kohana::modules(array(
// ... other modules ...
'pagination' => MODPATH.'pagination'
));
Copy the configuration file from modules/pagination/config/pagination.php to application/config/pagination.php.
Add the following actions to your controller:
public function action_index() {
// Go to first page by default
$this->request->redirect('yourcontroller/page/?page=1');
}
public function action_page() {
$orm = orm::factory('your_orm');
$pagination = Pagination::factory(array(
'total_items' => $orm->count_all(),
'items_per_page' => 20,
)
);
// Pass controller and action names explicitly to $pagination object
$pagination->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action()));
// Get data
$data = $orm->offset($pagination->offset)->limit($pagination->items_per_page)->find_all()->as_array();
// Pass data and validation object to view
echo View::factory('yourview/page', array('data' => $data, 'pagination' => $pagination));
}
Create yourview/page as follows:
<?php
foreach($data as $item) {
// ...put code to list items here
}
// Show links
echo $pagination;
Modify application/config/pagination.php according to your needs. I had to change the 'view' parameter to 'pagination/floating' which displays ellipses (...) when the list of pages is too large, unlike the default 'pagination/basic' which lists all pages regardless of length.
Pagination wasn't originally working/supported in Kohana 3.2. Luckily, somebody has updated the module and you can get the code at https://github.com/kloopko/kohana-pagination

Categories