I am using pdo connection, please help me how to get post views count.
How to create a post class and instance and functions variables after every post viewed by user it will add 1 view to the post. How to create function for this how to call want to print number of views below post. add a column to admin
Check this code
<?php $nRows = $db->query("select count(*) from comments WHERE :post_id = {$row['postID']} ")->fetchColumn();
Related
I'm new to symfony and the api platform and I want to develop an api with specific routes.
I'm looking to do is create a post query with nested resources to add relationships between tables.
example: I have 3 tables (users, periods, articles). I need to create a post request to add a new post with the following structure:
URL: api/:userid/:period/item
:userID = user ID
:period = Period name
name = element name
This request must create a new article in my "articles" table by adding the identifier, the name of the period and the name of the article entered as a parameter.
So my question is how do I pass multiple parameters in my path and save them in the database using the api platform?
Thanks in advance !
You can use custom routes with API platform, which allow you to create a route that correspond to a custom query => but you need to have these data before setting them in your Api platform path.
First of all, I would use the query builder to create the query you need get the data you need, then you can use your method directly in your entity (more here https://api-platform.com/docs/core/controllers/).
You can set the route you want inside of the path of the route and set the different arguments you need like this:
'path' => '/books/{id}/publication'
here id is your argument coming from your repository function.
I am writing an application and in one of my forms, I want to put in a listbox populated with all available tags from my client's InfusionSoft account. I am new to the InfusionSoft API and would greatly appreciate it if someone can point me toward the right direction.
Thanks
To get a list of all available tags, you'll want to query the ContactGroup table. That will return back a list of all available tags!
For example, if you were using the PHP iSDK, you could get the first 1,000 tags this way:
$app = new iSDK();
// perform authorization tasks
$returnFields = array('Id','GroupDescription', 'GroupName');
$query = array('GroupName' => '%');
$tags = $app->dsQuery("ContactGroup",1000,0,$query,$returnFields);
I'm not sure what is the way to do this , so here I ask:
I have a Person model and Event model, and a connection table Person_Event.
The interface that I got now works in the following way:
A person is logging in and his id is being send via URL
The person is selecting events he is interested in from the cGridView (checkbox column)
Writing some comment
4.Pressing send button , and the following create action is being triggered:
public function actionXcreate()
{
$model=new Person_Event;
if(isset($_POST['Person_Event']))
{
foreach ($_POST['selectedIds'] as $eventId)
{
$pmodel=new Person_Event;
$pmodel->person_id=$this->_person->id; //the id of the person who is logged in
$pmodel->attributes=$_POST['Person_Event']; //the comment
$pmodel->event_id = $eventId; //all the events he checked in the grid
if (!$pmodel->save()) print_r($pmodel->errors);
}
$this->redirect(array('site/success'));
}
So far , all is logical and simple. However , what I end up is that the comment the person wrote is being duplicated to every person_event row in the DB.
I want to put a text box in each row of the grid , and the commnet that will be written there will go to the specific event.
Now , I found this topic in yii about "admin-panel"
which is kind of helpful , BUT:
I already have a foreach in the action , the one that matches the person's id with the event's id , so how can I put another individual comment for each combo?
The default CGridView supports only basic functionality, you would need to extend CGridView or use an extension to make columns editable
Easiest way to do this is use something like TbEditableColumn from Yii-booster library
see http://yiibooster.clevertech.biz/extendedGridView#gridcolumns EditableColumn in the additional column types section
If you do not like or wish to use twitter-bootstrap styling a standalone extension like http://www.yiiframework.com/extension/eeditable will help.
Alternatively you can extend CGridView yourself to extend it to support column level editing
I have many clients send post to the server.
That is post url:
localhost/checkpost.php
parms:
id = "xxxx-xxxx-xxxx-xxxx"
<contents><name>user</name><detail>test<detail></contents>
I want check id and name with my database and save detail to my database.How can i do that?
Help me i am newbie in Yii?
You can access the get/post data with the CHttpRequest class. This is accessible as
$id = Yii::app()->request->getParam('id'); // Either GET or POST
$id = Yii::app()->request->getPost('id'); // POST only
$id = Yii::app()->request->getQuery('id'); // GET only
If you want to work with the database, the easiest is to implement an CActiveRecord-derived class and use that for interfacing with the database.
Here's the code I found in Yii framework manual:
$auth=Yii::app()->authManager;
$auth->createOperation('createPost','create a post');
$auth->createOperation('readPost','read a post');
$auth->createOperation('updatePost','update a post');
$auth->createOperation('deletePost','delete a post');
$bizRule='return Yii::app()->user->id==$params["post"]->authID;';
$task=$auth->createTask('updateOwnPost','update a post by author himself',$bizRule);
$task->addChild('updatePost');
$role=$auth->createRole('reader');
$role->addChild('readPost');
$role=$auth->createRole('author');
$role->addChild('reader');
$role->addChild('createPost');
$role->addChild('updateOwnPost');
and so on.
The question is Where should I place the code for creating roles, tasks, etc?
You should use this code in protected/controllers/RbacController.php
After modifing protected/config/main.php
return array(
'components'=>array(
'db'=>array(
'class'=>'CDbConnection',
'connectionString'=>'sqlite:path/to/file.db',
),
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
),
),
);
This is the official documentation:
http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#using-default-roles
This took me awhile to understand, so let me answer your questions as I understand how yii works.
You will first create the appropriate tables following the sql code found in framework/web/auth
You can use phpmyadmin to populate the database
You can also create a controller in which you will run all of code above. That gets run once, because you are just populating a database
The controller can be called myInitController.php and stored with your other controllers.
The controller can be as simple as
<?php
class myInitController extends Controller
{
public function actionRun()
{
$auth=Yii::app()->authManager;
$auth->createOperation('createPost','create a post');
echo "this is it";
}
}
Then you would run it by going to www.yourwebsite.com/myInit/Run
Verify what got written to the database. Don't push this controller to production. You don't want someone else running the command.
So your options are
hand enter data through something like phpmyadmin
create a customer controller which can store all of the php commands and execute
use gii to create models and CRUD functions (be careful of composite primary keys)
I hope this helps.
This piece of code will create the items in database. You have to execute it.
You can create an action in one of your controller and then run it.
localhost/myAppName/myController/myAction
Or you can create a php file as well. Then juste paste your piece of code inside and run it.