I'm building an image rating application, in which the main page is basically a grid of images with simple yes/no voting buttons at the bottom of each image.
I'm using Codeigniter for the server-side, Bootstrap (both CSS and JS) for the interface.
Now, I don't want to load all the images at once, but rather divide the images up to pages, wach page containing 10 images to reduce loading times.
I've been looking over the documentation # The CI Docs Which wants me to utilise a variation of this code:
$this->load->library('pagination');
$config['base_url'] = 'imgapp.com';
$config['total_rows'] = 100;
$config['per_page'] = 10;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
Which Produces This:
The problem is, I haven't built it in a way that enables URI segments.
So, the links are quite useless - they are pointing to an adress of this sort:
http://www.imgapp.com/default_controller/3
Which is useless for me.
How do I configure the pagination to work with my image app?
Check http://ellislab.com/codeigniter/user-guide/libraries/pagination.html
The keys to configure pagination are:
$config['uri_segment'] = 3;
The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.
$config['base_url'] = 'http://example.com/index.php/test/page/';
base_url This is the full URL to the controller class/function containing your pagination. In the example above, it is pointing to a controller called "Test" and a function called "page". Keep in mind that you can re-route your URI if you need a different structure.
Related
I have a working project on Codeigniter 3. Now I have to build a FAQ page and I had this doubt: do I need a Controller for every URL?
It is, the FAQ page is a static page, but CodeIgniter generally routes URLs to Controllers, like domain/controller/method. But it seems a waste to build a Controller to only load the View.
No, it's not right way to make controller for every page. Just make one function which shows page by fetching data from database.
First of all make a table named pages in your database then save page_content, page_name, permalink for your different pages.
Now suppose your default controller is home, make a function in it with name page as below.
function pages( $permalink )
{
// get page data based on page_name passed in URL
$this->db->where( array( 'permalink' => $permalink ) );
$data['page'] = $this->db->get( 'pages' )->result();
// load view and pass page object to view
$this->load->view( 'view_file', $data );
}
Now same function will show different page content based on permalink passed in URL.
For example if URL is www.example.com/index.php/home/pages/faq then content of faq page will be shown.
Is there a way to change the Url generated by the LinkPager in Yii2?
I have a page with results that are loaded with ajax when the search field is updated. But my pagination buttons links to a new page with the ajax-call url.
I looked in the files, and it seems like this function generates the url
public function createUrl($page, $pageSize = null, $absolute = false)
and that is not option to change. What is the way to solve this problem?
My results page is at the front page, but the pagination buttons links to ajax/results?page=2&page-size=10.
What can be more elegant then extending a class and replacing the renderPageButton function with your own :).
Another way, probably more the yii2 way :) if you take a look at LinkPager you will see that it is not responsible of creating the URLS. Pagination is https://github.com/yiisoft/yii2/blob/master/framework/data/Pagination.php#L257 The createUrl function in Pagination creates the URL and it takes into consideration the $route defined for the pagination object. If there is no $route defined then it takes the current controller's route. So by setting up $route for the pagination you can set the URL the buttons will go to.
I am using codeignietr pagination. I am facing a problem here.
The pagination numbers are coming in the page, but it is always fixed. Means if have total 8 pages, then I will click 5th page and it is going to the 5th page but from there if i click the next link it is not going to the 6th page, instead it is going to the 2nd page(the 1st page is always fixed or highlighted).
Currently If i click any page, only first page link only highlighting. I am expecting a code to highlight respective link on clicking on it.
Hello please set your $pagi_config['base_url'] correct.
Also please count correctly and set up $pagi_config['uri_segment'] correctly
in this particular case http://localhost/project_folder/articles //correctly set .htaccess + index.php removed is assumed
$pagi_config['base_url'] = base_url('articles/page'); //note that base_url() function is in url helper
$pagi_config['uri_segment'] = '3';
Please note that index() method in any controller does NOT accept any parameters! Anything written after controller name is considered as its method!
Also note that number generated by pagination library is not page number! It is offset!
Either use _remap(), or routes.php to make articles/<offset>, in routes case you still need extra method to take care of offset parameter.
On this part:
I am expecting a code to highlight respective link on clicking on it
Based on Codeigniter's docs, it should be something like this in your controller.
$config['num_tag_open'] = '<div class="current">';
$config['num_tag_close'] = '</div>';
You can than create a css style for .current and then whatever page you are on, the number will be styled.
I want to place articles and modules on my page. It should look like my scatch:
I am wondering if i can make 4 articles and one module (information box) and place this inbetween those articles, Or should i just create one article wich looks like the hole area (article 1-4 + INformation box)? So far i have tried to do {loadposition infobox-pos} into article 2. But than the box-width is not 100% but 50%.
Than aggain if i would make one big article with the contents from article 1-4 it would not fit great into my responsive layout.
I use T3-Framework.
Joomla doesn't support this natively, since module output is controlled by the template, and component output (in this case, com_content, view=category, layout=blog) is handled before modules are rendered.
You can proceed in many ways, I am listing them in order of decreasing ease:
Write a jquery script that moves the pieces in the browser. You could also use mootools and it's bundled with joomla, but odds are you already have jquery loaded anyways.
Write a view override for abovementioned view: so copy /components/com_content/view/category/tmpl to /templates/your_template/html/com_content/category (copy all files). Then edit blog.php and insert your module there, use something like /plugins/content/loadmodule/loadmodule.php :
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$modules = JModuleHelper::getModules($position);
$params = array('style' => $style);
foreach ($modules as $module) {
echo $renderer->render($module, $params);
}
Write a content plugin
you can also use {loadmodule YourCustomModuleTitle} and place this in <div> with custom style attributes like
<div style="width:100%;float:right">{loadmodule MyModule}</div>
or
<div class="something">{loadmodule MyModule}</div>
Note: the module which loaded must be assigned to the same menu item or "all"
I'm working on a new Wordpress theme; the default index view displays the excerpts of recent posts. Some posts will be regarding file downloads, and include an image, description, and link to the location where the described files are hosted. The images for these types of posts will be anchored with links(other types of posts may contain images that are not linked).
For these types of posts, I would like the images to link to their entry's full post views(single.php) when displayed in excerpts, but for the same images to link to an external download link when displayed as part of the full post view.
I'm not sure how exactly I would accomplish that.
Any help would be greatly appreciated!
Because I don't have post thumbnails defined, and since posts may or may not contain multiple images, I ended up doing it this way:
I turned off tags in excerpts(I had an excerpt plugin enabling tags in excerpt), then I added the following to the function.php file:
function catch_that_image() {
global $post, $posts;
$first_img = ''; ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
$post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
//Defines a default image
$first_img = "/images/default.jpg"; }
return $first_img;}
Then I added the following to the main index template file in between the posts title and the excerpt/content:
<p><img src="<?php echo catch_that_image() ?>"></p>
Random note: It's wrapped in a for styling reasons.
Thanx again for guiding me in the right direction.
if your theme uses 'the_excerpt()' for the front page, I think you can add a filter in functions.php, and with a regexp change the link href from the download link to the permalink.
something like,
function replace_link($content) {
if (is_home())
return preg_replace('regular_expression', get_permalink(), $content);
else
return $content;
}
add_filter('the_excerpt', 'replace_link');
I can't create an actual regular expression without knowing what your download link looks like