Mapping routes with static number in the middle - php

$route['9/(:num)/(:any)/1/(:num)'] = "web/organization/news/$1/$3";
$route['9/(:num)/(:any)/1'] = "web/organization/news/$1";
$route['9/(:num)/(:any)/2/(:num)'] = "web/organization/docs/$1/$3";
$route['9/(:num)/(:any)/2'] = "web/organization/docs/$1";
When paginating (1 record per page), the following url-s: http://www.mydomain.com/webapp/9/14/Name/1/2 and http://www.mydomain.com/webapp/9/14/Name/2/2 are giving me the same view.
First URL should give me the third page with news, but it gives me third page with documents.
I'm using Codeigniter 1.7.2

Related

Twilio Paging Information

Im using the Twilio PHP Sdk.
$AccountSid = env('TWILIO_SID');
$AuthToken = env('TWILIO_TOKEN');
$this->twi = new TwilioClient($AccountSid, $AuthToken );
And Im retrieving call logs like so.
$calls = $this->twi->calls->read(["to" => "+".$number->number], 15);
This is fine, and is returning 15 records of the latest calls.
But how do I access paging information such as how many total records are available, and how many pages are available to view. So that I can display some sort of pagination on my page??
I tried just accessing the Calls.json object, via CURL without using the SDK, like this...
$url = "https://api.twilio.com/2010-04-01/Accounts/".$AccountSid."/Calls.json?PageSize=15";
And that gave me a nice JSON object, with some paging info such as next_page_uri and previous_page_uri.
[previous_page_uri] =>/2010-04-01/Accounts/AC##########/Calls.json?PageSize=15&Page=0
[page_size] => 15
[start] => 0
[next_page_uri] => /2010-04-01/Accounts/AC##########/Calls.jsonPageSize=15&Page=1&PageToken=PACA27b63143f18c458f2abd35ef90753e5a
[page] => 0
But still, no totals such as total records, or total pages in the query??? So I cant display a nice bar of pagination at the bottom of my table, to show how many actual pages there are?
This seems dumb.
Is there no way to get this information?? Without actually storing the calls individually in my own database, so I can provide this manually?
Also.....one other question (assuming I cant retrieve that information)
I still want to be able to navigate from page to page, via the SDK instead of CURL requests. So....how do I pass the page number to the Twilio SDK? Ive tried...
$calls = $this->twi->calls->read(["To" => "+".$number->number,"Page"=>22], 15);
But it still just returns the first page. So how do I paginate these records via the SDK??
I am not sure about total pages, but for pagination i have used TWILIO PHP SDK's function,
Here how it will work,
//this will fetch first 10 calls
$calls = $twilio->calls->page([], 10, \Twilio\Values::NONE, 0);
//then you just need to call 2 methods for next and previous page
$nextPageData = $calls->nextPage(); //this will return data of next page
$previousPageData = $calls->previousPage(); // this will return data of previous page
// to check if current page has valid data
if(!$nextPageData->valid()){
//Invalid page
}
This is what i used for pagination on my project.

Hardcode page_list blog in Concrete5

Previously I've worked out how to hardcode content areas and the autonav block into my templates. I'm trying to do the same for a page_list which displays pages with a certain page type news entry, using pagination and just showing the title.
Here's how far I got:
<?php
$archive = BlockType::getByHandle("page_list");
$archive->controller->orderBy = "chrono_desc";
$archive->controller->ctID = "news";
$archive->controller->paginate = true;
$archive->render("view");
?>
But this doesn't seem to display any pages on the site. What have I done wrong?
It looks like you're supplying a page type handle instead of an page type ID to ctID.
You should be able to do something like so:
$sweetPageType = PageType::getByHandle('news');
if(is_object($sweetPageType)) { // let's be extra safe, eh?
$sweetPageTypeID = $sweetPageType->getPageTypeID();
}
And then, in your hardcoded block (you could test that you have an ID, although I think if it's null it would just have no effect):
$archive->controller->ctID = $sweetpageTypeID;
Dunno if you're using 5.6 or 5.7 but I believe it should be the same for both. Here's a relevant link to the c5 API:
http://concrete5.org/api/class-Concrete.Core.Page.Type.Type.html

Joomla Infinite Scrolling mysql pagination issues

I have set up infinite scrolling on a Joomla based website to load db results from mysql query. It works fine but when I have it set up to load 10 results at a time, it skips results 11-20 and then loads the rest of the values, and likewise when I set up to show 20 results it loads the first 40 without any repeats, and then proceeds to load 10 previouss results and 10 new ones for each new pagination result until it reaches the end of the list. Here is the code I have for pagination,
//
jimport('joomla.html.pagination');
// prepare the pagination values
$total = $this->xyz->getTotal('posts',' and cat_id = ' . $cat->cat_id);
$limit = $mainframe->getUserStateFromRequest('global.list.limit','limit', $mainframe->getCfg('list_limit'));
$limitstart = $mainframe->getUserStateFromRequest(JRequest::getVar('option').'limitstart','limitstart', 0);
$this->items = $this->xyz->categoryItems(JRequest::getInt('cat_id'),$limitstart,$limit);
// create the pagination object
$_pagination = new JPagination($total, $limitstart,$limit);
$_pagination_footer = $_pagination->getListFooter();
//
I should mention that I set the $limit value to 10 on line 7 of the code above to make it load 10 at a time. If it is left as $limit it loads 20 at a time.
Preferably I would like to load 50 at a time without any repeats or omissions but as it is now, I get plenty of repeats when set to 50. I found that setting it to 10 gives me the best results but still skips 11-20.
Any suggestions or thoughts would be greatly appreciated.
Had similar problems on two different occasions
1) SEF turned off
You might want to debug global.list.limit to check for consistency in values it loads
2) SEF turned on
Look for inconsistent entries in the redirection base for the same sef url.

How can I get an id from a simplepie post which can be used to look it up later?

I've recently started developing a portfolio website which I would like to link to my wordpress blog using simplepie. It's been quite a smooth process so far - loading names and descriptions of posts, and linking them to the full post was quite easy. However, I would like the option to render the posts in my own website as well. Getting the full content of a given post is simple, but what I would like to do is provide a list of recent posts which link to a php page on my portfolio website that takes a GET variable of some sort to identify the post, so that I can render the full content there.
That's where I've run into problems - there doesn't seem to be any way to look up a post according to a specific id or name or similar. Is there any way I can pull some unique identifier from a post object on one page, then pass the identifier to another page and look up the specific post there? If that's impossible, is there any way for me to simply pass the entire post object, or temporarily store it somewhere so it can be used by the other page?
Thank you for your time.
I stumbled across your question looking for something else about simplepie. But I do work with an identifier while using simplepie. So this seems to be the answer to your question:
My getFeedPosts-function in PHP looks like this:
public function getFeedPosts($numberPosts = null) {
$feed = new SimplePie(); // default options
$feed->set_feed_url('http://yourname.blogspot.com'); // Set the feed
$feed->enable_cache(true); /* Enable caching */
$feed->set_cache_duration(1800); /* seconds to cache the feed */
$feed->init(); // Run SimplePie.
$feed->handle_content_type();
$allFeeds = array();
$number = $numberPosts>0 ? $numberPosts : 0;
foreach ($feed->get_items(0, $number) as $item) {
$singleFeed = array(
'author'=>$item->get_author(),
'categories'=>$item->get_categories(),
'copyright'=>$item->get_copyright(),
'content'=>$item->get_content(),
'date'=>$item->get_date("d.m.Y H:i"),
'description'=>$item->get_description(),
'id'=>$item->get_id(),
'latitude'=>$item->get_latitude(),
'longitude'=>$item->get_longitude(),
'permalink'=>$item->get_permalink(),
'title'=>$item->get_title()
);
array_push($allFeeds, $singleFeed);
}
$feed = null;
return json_encode($allFeeds);
}
As you can see, I build a associative array and return it as JSON what makes it really easy using jQuery and ajax (in my case) on the client side.
The 'id' is a unique identifier of every post in my blog. So this is the key to identify the same post also in another function/on another page. You just have to iterate the posts and compare this id. As far as I can see, there is no get_item($ID)-function. There is an get_item($key)-function but it is also just taking out a specific post from the list of all posts by the array-position (which is nearly the same way I suggest).

Zendframework Routing Issue [duplicate]

This question already has an answer here:
PHP Zend Route Config.ini - similar patterns
(1 answer)
Closed 2 years ago.
I have been setting my routes in my application.ini file which works for all the ones i have setup. The problem is when there are multiple actions within that controller and i try to use the routes in other actions.
For instance i have created the following in my application.ini for paging and column sorting
resources.router.routes.search.route = "search/:page/:col/:sort/:limit/"
resources.router.routes.search.defaults.controller = search
resources.router.routes.search.defaults.page = 1
resources.router.routes.search.defaults.col = time
resources.router.routes.search.defaults.sort = default
resources.router.routes.search.defaults.limit = 50
resources.router.routes.search.reqs.page = \d+
resources.router.routes.search.reqs.col = \w+
resources.router.routes.search.reqs.sort = \w+
resources.router.routes.search.reqs.limit = \d+
The above works when I'm on the default action of that page like
www.mywebsite.com/search/2/
Would bring up the second page of the results. But if I try the same on another action,
www.mywebsite.com/search/action/2
It just shows a blank page. I tried creating its own settings in the ini and that did not work. I've run across this problem before but usually just gave up and separated things into different controllers but i would rather have different actions.
Any help would be much appreciated.
Matt
search/:page/:col/:sort/:limit/ doesn't match www.mywebsite.com/search/action/2. Your route is looking for search/ followed by a digit (\d) that represents the page number; however, you're requesting search/ followed by the string action. I would suggest adding another parameter to your route: search/:action/:page/:col/:sort/:limit, defaulting action to index.
Requesting the first page of the default action stays the same (search). Requesting page 2 of the default route will now be search/index/2/, but you can now specify a different action (search/action/2).

Categories