How to update record in bolt CMS ??

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

How to update record in bolt CMS ??

Post by gautamz07 »

In my records.twig file i have this variable record ... which has a property views , now views is of integer type in the database , With a default value of 0 , Now everytime the record.twig template is loaded , i want to update the value of the views property in the database. How do i do this in bolt ?? So the update statement will be something like:

Update the views property ... where the ID is equal to the current record ID.

Now ofcouse i can do some hardcording like the following:

Code: Select all

   $db = new PDO('mysql:host=localhost;dbname=peckinga_tinyblog', 'peckinga_general', 'gautam');  
   // Update views
   $query = "UPDATE tinyblog SET views = views + 1 WHERE id = :views_id";
   $stmt = $db->prepare($query);
   $stmt->execute(array(":views_id"=>$article_id));
But is there a bolt specific way of doing this or a more efficient way ??
User avatar
Celauran
Moderator
Posts: 6425
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How to update record in bolt CMS ??

Post by Celauran »

User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: How to update record in bolt CMS ??

Post by gautamz07 »

Celauran ! Awesome .. thanks aloot :)
Post Reply