نمایش نتایج 1 تا 9 از 9

نام تاپیک: Tag Cloud Portlet

  1. #1
    کاربر تازه وارد
    تاریخ عضویت
    اردیبهشت 1393
    پست
    31

    Tag Cloud Portlet

    سلام من بعد از ساختن Tag Cloud Portlet

    ه‌ر کاری که میخوام بکنم این ارور میاد


    The table "{{tag}}" for active record class "Tag" cannot be found in the database.






    components/TagCloudPortlet

    کد PHP:

    php?>
    Yii::import(’zii.widgets.CPortlet’);
    class TagCloud extends CPortlet {
    public $title=’Tags’;
    public $maxTags=20;
    protected function renderContent() {
    $tags=Tag::model()->findTagWeights($this->maxTags);
    foreach($tags as $tag=>$weight) {
    } }
    }






    postcontroller

    کد PHP:

    /**
    * Suggests tags based on the current user input.
    * This is called via AJAX when the user is entering the tags input.
    */
    public function actionSuggestTags()
    {
    if(isset($_GET['q']) && ($keyword=trim($_GET['q']))!=='')
    {
    $tags=Tag::model()->suggestTags($keyword);
    if($tags!==array())
    echo implode("\n",$tags);
    }
    }


    آخرین ویرایش به وسیله >@>mehr : چهارشنبه 07 خرداد 1393 در 14:37 عصر

  2. #2
    کاربر تازه وارد
    تاریخ عضویت
    اردیبهشت 1393
    پست
    31

    نقل قول: Tag Cloud Portlet

    <?php




    class Tag extends CActiveRecord
    {


    /**
    * The followings are the available columns in table 'tbl_tag':
    * @var integer $id
    * @var string $name
    * @var integer $frequency
    */


    /**
    * Returns the static model of the specified AR class.
    * @return CActiveRecord the static model class
    */
    public static function model($className=__CLASS__)
    {
    return parent::model($className);
    }


    /**
    * @return string the associated database table name
    */
    public function tableName()
    {
    return '{{tag}}';
    }


    /**
    * @return array validation rules for model attributes.
    */
    public function rules()
    {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
    array('name', 'required'),
    array('frequency', 'numerical', 'integerOnly'=>true),
    array('name', 'length', 'max'=>128),
    );
    }


    /**
    * @return array relational rules.
    */
    public function relations()
    {
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
    );
    }


    /**
    * @return array customized attribute labels (name=>label)
    */
    public function attributeLabels()
    {
    return array(
    'id' => 'Id',
    'name' => 'Name',
    'frequency' => 'Frequency',
    );
    }


    /**
    * Returns tag names and their corresponding weights.
    * Only the tags with the top weights will be returned.
    * @param integer the maximum number of tags that should be returned
    * @return array weights indexed by tag names.
    */
    public function findTagWeights($limit=20)
    {
    $models=$this->findAll(array(
    'order'=>'frequency DESC',
    'limit'=>$limit,
    ));


    $total=0;
    foreach($models as $model)
    $total+=$model->frequency;


    $tags=array();
    if($total>0)
    {
    foreach($models as $model)
    $tags[$model->name]=8+(int)(16*$model->frequency/($total+10));
    ksort($tags);
    }
    return $tags;
    }


    /**
    * Suggests a list of existing tags matching the specified keyword.
    * @param string the keyword to be matched
    * @param integer maximum number of tags to be returned
    * @return array list of matching tag names
    */
    public function suggestTags($keyword,$limit=20)
    {
    $tags=$this->findAll(array(
    'condition'=>'name LIKE :keyword',
    'order'=>'frequency DESC, Name',
    'limit'=>$limit,
    'params'=>array(
    ':keyword'=>'%'.strtr($keyword,array('%'=>'\%', '_'=>'\_', '\\'=>'\\\\')).'%',
    ),
    ));
    $names=array();
    foreach($tags as $tag)
    $names[]=$tag->name;
    return $names;
    }


    public static function string2array($tags)
    {
    return preg_split('/\s*,\s*/',trim($tags),-1,PREG_SPLIT_NO_EMPTY);
    }


    public static function array2string($tags)
    {
    return implode(', ',$tags);
    }


    public function updateFrequency($oldTags, $newTags)
    {
    $oldTags=self::string2array($oldTags);
    $newTags=self::string2array($newTags);
    $this->addTags(array_values(array_diff($newTags,$oldTags )));
    $this->removeTags(array_values(array_diff($oldTags,$newT ags)));
    }


    public function addTags($tags)
    {
    $criteria=new CDbCriteria;
    $criteria->addInCondition('name',$tags);
    $this->updateCounters(array('frequency'=>1),$criteria) ;
    foreach($tags as $name)
    {
    if(!$this->exists('name=:name',array(':name'=>$name)))
    {
    $tag=new Tag;
    $tag->name=$name;
    $tag->frequency=1;
    $tag->save();
    }
    }
    }


    public function removeTags($tags)
    {
    if(empty($tags))
    return;
    $criteria=new CDbCriteria;
    $criteria->addInCondition('name',$tags);
    $this->updateCounters(array('frequency'=>-1),$criteria);
    $this->deleteAll('frequency<=0');
    }


    }

  3. #3
    کاربر تازه وارد
    تاریخ عضویت
    اردیبهشت 1393
    پست
    31

    نقل قول: Tag Cloud Portlet

    تیبل تگ هم اینگونه ساخته شده

    CREATE TABLE tag
    (
    id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(128) NOT NULL,
    frequency INTEGER DEFAULT 1
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

  4. #4

    نقل قول: Tag Cloud Portlet

    تنظیمات کامپوننت db رو از فایل config/main.php بگذارین.

  5. #5
    کاربر تازه وارد
    تاریخ عضویت
    اردیبهشت 1393
    پست
    31

    نقل قول: Tag Cloud Portlet

    	'components'=>array(		'user'=>array(			// enable cookie-based authentication			'allowAutoLogin'=>true,		),

  6. #6

    نقل قول: Tag Cloud Portlet

    نه تنظیمات کامپوننت db رو میخوام نه خود component رو. محتوای main.php رو بگذارین اصلاً

  7. #7
    کاربر تازه وارد
    تاریخ عضویت
    اردیبهشت 1393
    پست
    31

    نقل قول: Tag Cloud Portlet

    <?php
    // uncomment the following to define a path alias
    // Yii::setPathOfAlias('local','path/to/local-folder');
    // This is the main Web application configuration. Any writable
    // CWebApplication properties can be configured here.
    return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR. '..',
    'name'=>'Bargue',
    // preloading 'log' component
    'preload'=>array('log'),
    // autoloading model and component classes
    'import'=>array(
    'application.models.*',
    'application.components.*',
    ),
    'modules'=>array(
    // uncomment the following to enable the Gii tool
    'gii'=>array(
    'class'=>'system.gii.GiiModule',
    'password'=>'pa$$word',
    // If removed, Gii defaults to localhost only. Edit carefully to taste.
    'ipFilters'=>array('127.0.0.1','::1'),
    ),
    ),
    // application components
    'components'=>array(
    'user'=>array(
    // enable cookie-based authentication
    'allowAutoLogin'=>true,
    ),
    // uncomment the following to enable URLs in path-format
    'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
    ),
    /*
    'db'=>array(
    'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
    ),
    */
    // uncomment the following to use a MySQL database
    'db'=>array(
    'connectionString' => 'mysql:host=localhost;dbname=mydb',
    'emulatePrepare' => true,
    'username' => 'user',
    'password' => 'pa$$word',
    'charset' => 'utf8',
    ),
    'errorHandler'=>array(
    // use 'site/error' action to display errors
    'errorAction'=>'site/error',
    ),
    'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
    array(
    'class'=>'CFileLogRoute',
    'levels'=>'error, warning',
    ),
    // uncomment the following to show log messages on web pages
    /*
    array(
    'class'=>'CWebLogRoute',
    ),
    */
    ),
    ),
    ),
    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params'=>array(
    // this is used in contact page
    'adminEmail'=>'webmaster@example.com',
    ),
    );
    آخرین ویرایش به وسیله MMSHFE : پنج شنبه 08 خرداد 1393 در 20:31 عصر دلیل: اصلاح تگ

  8. #8

    نقل قول: Tag Cloud Portlet

    خوب توی این هم مشکل خاصی به چشمم نمیاد. بقیه مدلها درست کار میکنن؟ این رو به کامپوننت db اضافه کنید ببینید درست میشه؟
    'db'=>array(
    ...
    'tablePrefix' => 'tbl_',
    ),

  9. #9
    کاربر تازه وارد
    تاریخ عضویت
    اردیبهشت 1393
    پست
    31

    نقل قول: Tag Cloud Portlet

    بله بقیه مدل‌ها درست کار می‌کنند
    حتی خود تگ هم درست کار میکنه، می‌تونم تگ‌های وارد شده در یک پست را نمایش بدم.
    کاری که شما گفتین رو کردم بازم درست نشد

تاپیک های مشابه

  1. tag - value ???
    نوشته شده توسط puissance در بخش VB.NET
    پاسخ: 1
    آخرین پست: شنبه 07 خرداد 1384, 15:34 عصر
  2. how replace tag in the string ?
    نوشته شده توسط Silverboy در بخش ASP.NET Web Forms
    پاسخ: 7
    آخرین پست: یک شنبه 11 اردیبهشت 1384, 17:31 عصر
  3. meta tag چیه؟!!
    نوشته شده توسط Mohammad Minaei در بخش Classic ASP
    پاسخ: 4
    آخرین پست: دوشنبه 24 اسفند 1383, 19:04 عصر
  4. Microsoft Internet Explorer IFRAME Tag Overflow
    نوشته شده توسط Developer Programmer در بخش امنیت در شبکه
    پاسخ: 2
    آخرین پست: پنج شنبه 21 آبان 1383, 11:05 صبح
  5. tag html
    نوشته شده توسط bebakhshid در بخش طراحی وب (Web Design)
    پاسخ: 1
    آخرین پست: شنبه 14 شهریور 1383, 08:56 صبح

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •