I am using the following plugin in my webpage:
http://www.nickstakenburg.com/projects/lightview/
The script works great in terms of displaying the photos and everything else it is supposed to do, however, I would like to accomplish the following I havent been able to:
Have the plugin increment view count everytime an image is displayed
I have created the following action in my photo.php model, but I can't figure out a way to call using the Plugin:
function incrementViewCount($id) {
$this->updateAll(
array('Photo.viewed' => 'Photo.viewed+1'),
array('Photo.id' => $id)
);
}
I have it setup per the following on my site:
<?php
foreach ($photocategory['Photo'] as $photo){
?>
<li>
<a
href="/img/uploads/photos/<?php echo photo['photocategory_id']."/".$photo['image']; ?>"
class="lightview"
data-lightview-group="shared_options"
>
<img
style="width:155px;height:113px;"
src="/img/uploads/photos/<?php echo $photo['photocategory_id']."/thumb/".$photo['image']; ?>"
alt=""
/>
</a>
</li>
<?php } ?>
If anyone knows anything about this plugin or jQuery and if you can suggest a way to accomplish this, it would be great!
If you are using CakePHP this
https://github.com/sliker/CakePHP-Counter-Plugin may help.
Has simple call methods for incrementing counter.
Related
I am beginner in code igniter php framework. Today I have a task to modify existing code and somehow I am lost in the middle of the line on attempting to located a database table. This is the controller snippet that renders the view
..........
$data["all_types"] = $this->data_model->get_data("all_types",300,"Asc");
$this->load->view("preview_brands",$data);
...........
when the view is loaded I am iterating through the in the view to load data as shown
<div class="decoration"></div>
<?php foreach($all_types as $item): ?>
<div style="display:block;color:#000;">
<a style="font-size:17px;margin:15px 2px;font-family:Cgothic;"
href="<?php echo site_url()."...../..../".$item["id"]; ?>"
class="scale-hover"
title="<?php echo str_replace("_"," ",$item["name"]);?>">
<strong><?php echo str_replace("_"," ",$item["name"]);?></strong>
</a>
</div>
<?php endforeach; ?>
this is the model snippet code as shown
function get_data($db,$i,$order)
{
$this->db->order_by("name",$order);
$this->db->where('consent',"yes");
$query=$this->db->get($db);
return $query->result_array();
}
My challenge is how can I locate or identify the database table the above model is pointing to to fetch data. Hoping someone assists me
all_types is your table name.
$this->db->get($your_table name), get method take table name as a parameter.
Get Method Documentation
If more help needed I'm happy to help.
Happy Coding.
From your model code:
$query=$this->db->get($db);
This means $db is the table name. Looking at your controller code which calls the model function:
$data["all_types"] = $this->data_model->get_data("all_types",300,"Asc");
I can say that all_types is the name of the table.
Im stuck on wired situation. The thing i do is getting magento blog data and show on specific page. The problem is magento return the wrong media URL on front end like this <img alt="" src="{{media url=" wysiwyg="" blogimg1.jpg"}}"="">. All i want it will return image src like this "mydomain.com/images/blogimg1.jpg". I try to find solution but couldnot succeed.
My code is below
<?php
$collections = Mage::getModel('blog/blog')->getCollection()
->addPresentFilter()
->addEnableFilter(AW_Blog_Model_Status::STATUS_ENABLED)
->addStoreFilter()
->joinComments()
->setOrder('created_time', 'desc');
foreach ($collections as $collection) {
echo $collection->title."<br>";
echo $collection->post_content."<br>";
echo $collection->short_content."<br>";
}
?>
Problem solve we have to use the filter , and everything gonna fine
Mage::helper('cms')->getPageTemplateProcessor()->filter($collection->short_content)
Ok, so this question may be very simple and I'm just missing something basic but here goes. My website I'm currently building is developed in Codeigniter. It's a site for exercises.
Now one of my functions (biceps) calls a model (model_get) that grabs data from my database and then passes it into a view (content_biceps.php)
So to try and explain this best as possible here is my controller model and view for this.
Controller function:
public function biceps(){
if($this->session->userdata("is_logged_in")){
$this->load->model("model_get");
$data["results"] = $this->model_get->getExercises("1");
$this->load->view("site_header");
$this->load->view("site_nav");
$this->load->view("site_sidebar");
$this->load->view("content_biceps", $data);
$this->load->view("site_footer");
} else {
redirect ("site/restricted");
}
}
Model function get_data:
function getData($page){
$query = $this->db->get_where("pagedata", array("page" => $page));
return $query->result();
}
View content_biceps:
foreach($results as $row){
echo '<div class="item">
<h2>'.$row->name.'</h2>
<img src="'.$row->image.'" alt="'.$row->name.'" />';
$e_id = $row->e_id;
echo $e_id;
echo form_submit('exercise_submit', 'view');
echo '</div>';
echo form_close();
}
Now this view works great, it grabs the data i need such as the name, image and e_id for each exercise and displays them all.
If you notice the submit button named 'view'. If you can imagine all of these exercises displayed on one page. They all have a unique e_id. I want it so that when i click the view button on a certain exercise, i am taken to a page view such as 'exercise_view' where i can use the e_id to grab the data for that particular exercise. At the moment I dont know how to take the e_id when i click view and use it in another page.
Any help would be great.
You can try to add an input with the e_id you want, for example
<div>
<input type="hidden" name="e_id" value="{$e_id}" />
<input type="submit" name="view" />
</div>
then in controller, you can get the e_id
$e_id = $this->input->post('e_id');
I have several links in my Magento template file. If a user is currently viewing a page that is one of the links I would like that link to display the CSS class "active". How could I achieve this?
$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
The above variable $routeName can be used to check whether the current page is a CMS page. The other variable $identifier will output the page identifier.
Magento assigns classes to each page individually
The easiest way to get active states was to to assign each link a class and then write a CSS role for the specific body class and link class.
body.page-a a.class-a {
color:red}
body.page-b a.class-b {
color:red}
<body class="page-b">
<a class="class-a">page a</a>
<a class="class-b">page b</a>
</body>
Create an array that contains all the links (or pages)
$urls = array('home.php', 'about.php', 'contact.php');
Then compare the current url with the one in the array:
<li><a href="about.php" <?php if(in_array($current_url, $urls))
{ echo 'class="active"'; } ?>>About Us</a></li>;
in the controller i have :
$paginator = Zend_Paginator::factory($mdlPost->getPosts($this->moduleData->accordion, 'name ASC'));
if(isset($params['cities'])) {
$paginator->setCurrentPageNumber(intval($params['cities']));
}
$paginator->setItemCountPerPage(4);
$this->view->posts = $paginator;
in the view's i have some thing like this :
if ($this->posts != null) {?>
<div id="cities_accord" class="news">
<?php echo $this->partialLoop('partials/post-min.phtml', $this->posts); ?>
</div>
<?php echo $this->paginationControl($this->posts,
'Sliding',
'public/pagination_cont.phtml');
}
the partial/post-min.phtml
<?php
$color = array(1=>'spring',2=>'summer',3=>'autumn',4=>'winter');
?>
<div id='<?php echo $color[$this->partialCounter] ?>' class="accordion_post">
<?php
$link = Digitalus_Uri::get(false, false, array('openCity' =>
$this->id));//$color[$this->partialCounter]));
?>
<h1 class="accordion_post_title"><?php echo $this->title ?></h1>
<p><?php echo $this->teaser ?> <i>read more</i></p>
</div>
the pagination_cont.phtml taken from this link zend ( http://framework.zend.com/manual/en/zend.paginator.usage.html )
will show links that will pass params to the controller to fetch the corresponding whole page which is working alright for now
but i want to change this so that i will be able ajaxify the returned ( i.e. only a single paginated value rather than reloading the whole page ) results how can i do that using jquery and what should i change ..
** EDIT: it would be nice to have a fail-save ,if possible, for browsers(users) that disabled javascript to see the same thing by reloading the page (i.e. keeping the current status for if(javascript_not_enabled ))**
This is what I've done in the past.
First, setup the AjaxContext action helper to enable the html context on your controller action.
Add a .ajax.phtml view that just contains the section of markup that may be replaced via AJAX as well as the pagination control links. You can probably just copy this out of your normal view. Replace that section in your normal view with something like
<div id="reloadable-content">
<?php echo $this->render('controller/action.ajax.phtml') ?>
</div>
This will ensure that your initial and any non-AJAX requests will still include the right content. The <div> id is purely for referencing the loadable block in JavaScript.
Also make sure you include your JS file (using headScript) in the normal view only.
Now, in your JS file, unobtrusively add the appropriate event binding to the paginator links. As you'll be replacing the pagination control section in order to reflect the correct current page and other links, it's probably best to do this using the jQuery live binding. I'm also assuming you'll wrap the pagination control with some kind of identifiable element (<div class="pagination-control"> for example)
$('.pagination-control').find('a').live('click', function(e) {
var link = $(this);
$('#reloadable-content').load(link.attr('href'), { format: 'html' });
return false;
});
Keep in mind that in using this method, you will lose the ability to navigate the paged requests using the normal back / forward browser buttons. You will also lose the ability to bookmark pages directly (though you could always provide a permanent link to the current page as part of the AJAX loaded content).
You can use something like the jQuery history plugin if you're really concerned but that will require more client-side work.
Another caveat is that the above will only work with pagination links. If you want to use a form with dropdown page selection, you need to add another event handler for the submission.
GOT IT and big Thanks to #Phil Brown :
in the controller int() change the response type to json
class NewsController extends Zend_Controller_Action
{
public function init()
{
$contextSwitch = $this->_helper->getHelper('contextSwitch');
$contextSwitch->addActionContext('list', 'JSON')
->initContext();
}
// ...
}
public listAtcion() {
// .............
$paginator = Zend_Paginator::factory($mdlPost->getPosts($this->moduleData->accordion, 'name ASC'));
if(isset($params['cities'])) {
$paginator->setCurrentPageNumber(intval($params['cities']));
}
$paginator->setItemCountPerPage(4);
$post = array();
foreach($paginator as $post ) {
$post[] = $post;
}
$this->view->post = $paginator;
#TODO //add a check here for non-ajax requests (#improvment)
$this->view->posts = $paginator;
}
in one of the views (most probably in the pagination_cont.phtml) on the pagination controller add the ajax links
<?= $this->ajaxLink (
$this->url('cities'=>$this->page_num),array('id'=>'div_id','complete'=>'js_method(json_data)','method'=>post) ,array('format'=>'JSON'));
and add a JavaScript function of js_method(json_data) to modify the div with id = 'div_id' with a json data
function js_method(json_data) {
var content = parse.JSON(json_data);
$('#div_id').html('');
//fill it with the reposnse content some thing like $('#div_id').append(content);
}