GithubHelp home page GithubHelp logo

Relation model? about yii2-vote HOT 18 CLOSED

chiliec avatar chiliec commented on July 28, 2024
Relation model?

from yii2-vote.

Comments (18)

chiliec avatar chiliec commented on July 28, 2024

Hi @Pablossoo and thank you for your interest in this module!

You need a mysql database (not tested in other databases). Table should have a primary key (PK). And model for this table, for example Post.

In module settings you can to set like this:

'models' => [
    123 => \common\models\Post::className()
],

where key 123 - id for link model in module auxiliary tables, value - path to class name definition (this needs for reduce table size - we stored only integer key).

If you have problems with integration module, feel free to ask any questions!

from yii2-vote.

Pablossoo avatar Pablossoo commented on July 28, 2024

Ok, let me explain my problem more precisely.

My entity model

class Adresssite extends \yii\db\ActiveRecord
{

public static function tableName()
 {
   return 'adresssite';
 }

  public function rules()
   {
      return [
         [['adress'], 'string', 'max' => 255],
         [['adress'], 'unique'],
      ];
 }


  public function attributeLabels()
    {
       return [
           'id_adress' => 'Id Adress',
           'adress' => 'Adress',
       ];
      }
 }

Now if I set all config like as tutorial, but I use a basic app yii2- it's any problem?

 'bootstrap' => ['log',
      'chiliec\vote\components\VoteBootstrap',
  ],
 'vote' => [
        'class' => 'chiliec\vote\Module',
        // show messages in popover
        'popOverEnabled' => true,
        // global values for all models
        // 'allowGuests' => true,
        // 'allowChangeVote' => true,
        'models' => [
            // example declaration of models
                 //   app\models\Adresssite::className(),   if unncoment  gets Uncaught Error: Class 'app\models\Adresssite' not found in... 
            // 'backend\models\Post',
            // 2 => 'frontend\models\Story',
            // 3 => [
            //     'modelName' => \backend\models\Mail::className(),
            //     you can rewrite global values for specific model
            //     'allowGuests' => false,
            //     'allowChangeVote' => false,
            // ],
        ],

        ],

in next step I put widget to view

 echo \chiliec\vote\widgets\Vote::widget([
    'model' => $data,
    // optional fields
    // 'showAggregateRating' => true,
 ]);

but if I try click voteup or vote down I get error

 SyntaxError: expected expression, got ','

What is differance beetwen model agregate and agreagate_rating?

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024

I use a basic app yii2- it's any problem?

It's not a problem. I think your model not in app\models\. Before class declaration you watch line like namespace app\models; ?

but if I try click voteup or vote down I get error
SyntaxError: expected expression, got ','

uncomment this line too:

screenshot 2016-12-01 17 01 14

What is differance beetwen model agregate and agreagate_rating?

aggregate contains all votes, aggregate_rating contains only aggregate data for every id (this needs for improving performance).

from yii2-vote.

Pablossoo avatar Pablossoo commented on July 28, 2024

Still not working but...
I can;t use app\models\Adresssite::className(), only class, now i doesn't get an error (class not found). My entity has namespace app\models.
But still show error SyntaxError: expected expression, got ','

my new config

        'vote' => [
        'class' => 'chiliec\vote\Module',
        // show messages in popover
        'popOverEnabled' => true,
        // global values for all models
        // 'allowGuests' => true,
        // 'allowChangeVote' => true,
        'models' => [
            app\models\Adresssite::class,
        ],
    ],

Ok I think find error. In console at onclick function
onclick="vote(0, , 'like');
onclick="vote(0, , 'dislike');

How it fix?

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024

::class not the same to ::className(). Hmm, try to change config like this:

'models' => [
    ['modelName' => 'app\models\Adresssite'],
],

from yii2-vote.

Pablossoo avatar Pablossoo commented on July 28, 2024

Ok, it's resolve this problem. Now what is second problem with onclick?

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024

Are you sure that your model have Primary key? Because you didn't have target id (which is primaryKey()[0])

from yii2-vote.

Pablossoo avatar Pablossoo commented on July 28, 2024

Ya, he has PK, look

https://gyazo.com/4f50997666b667bf2c4710dacdc43694

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024
var_dump($this->primaryKey());

Can you exec this code in model and write result here?

from yii2-vote.

Pablossoo avatar Pablossoo commented on July 28, 2024

Ya, I created new method with this code and I called in view.

$model->myAction();

result;

array(1) { [0]=> string(9) "id_adress" }

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024

Fine! Now try exec:

var_dump($this::className());

from yii2-vote.

Pablossoo avatar Pablossoo commented on July 28, 2024

string(21) "app\models\Adresssite"

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024

Great! In module config written this string?

from yii2-vote.

Pablossoo avatar Pablossoo commented on July 28, 2024
'modules' => [

    'vote' => [
        'class' => 'chiliec\vote\Module',
        // show messages in popover
        'popOverEnabled' => true,
         'allowGuests' => true,
         'allowChangeVote' => true,
        'models' => [

            ['modelName' => 'app\models\Adresssite'],
        ],
    ],

....
]

className() still not working.

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024

Very strange, it should work :(
Is your project located in somewhere in open source?

from yii2-vote.

Pablossoo avatar Pablossoo commented on July 28, 2024

OK.
so it's application;
https://github.com/Pablossoo/basic
Controller it siteController , action actionShowCommentSite($id) (she render view)
view/site/site.php

config you have in config folder.

if you want I can sent my database sql file and maybe you try reproduce my issue.

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024

Sure, put your sql file in this repository.

from yii2-vote.

chiliec avatar chiliec commented on July 28, 2024

Closed because no response for a long time.

from yii2-vote.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.