0

私はこのような2つのテーブルを持っています:

CREATE TABLE `tblFacilityHrs` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `uid` varchar(45) DEFAULT NULL,
          `title` varchar(100) DEFAULT NULL,
          `description` text,
          PRIMARY KEY (`id`),
          KEY `key_uid` (`uid`)
        ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1$$

        CREATE TABLE `tblFacilityHrsDateTimes` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `owner_uid` varchar(45) DEFAULT NULL,
          `startDate` date DEFAULT NULL,
          `endDate` date DEFAULT NULL,
          `startTime` time DEFAULT NULL,
          `endTime` time DEFAULT NULL,
          `days` int(2),
          `recurrence` int(1) DEFAULT NULL,
          PRIMARY KEY (`id`),
          KEY `fk_fh_owneruid` (`owner_uid`),
          CONSTRAINT `fk_fh_owneruid` FOREIGN KEY (`owner_uid`) REFERENCES `tblFacilityHrs` (`uid`) ON DELETE CASCADE ON UPDATE CASCADE
        ) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=latin1$$

iduidタイトル説明場所
8ada0ceabd40d509c3fb38f2822a97de11bc6628スイムレッスン親と子のクラスCRC 2 543a6ed0005ff6a0a7fc99cc2f9715d86804ecb0スイムレッスン、レベル1、セッション1 3 7d219b64be6dc706135bdad3e7c2f0d56cb7f353スイムレッスン、レベル2 4 f7c91e2f1daa9c696c22f5aa5736c167d1ba9f94スイムレッスン、レベル3 5 262f06fb75645248162aa983f610ec7959a2011bスイムレッスンレベル4 6 51f9f552ffc5fa4bc8b4e7f914fb22b3b0920c2eバイク275本プログラムに参加し、4つのフィットネスサイクリングクラスを取り、 FREEWaterbottleを手に入れよう!参加者は1回のみ登録できます。これは無料のプログラムです!多目的ルームにサインアップします。7 0cca3515ec8ee990c863e474fee634ae94d382c2フィットネスへのパスポート北欧のフィットネスクラスを受講し、パスポートにスタンプを押して、無料のTシャツを獲得しましょう!4月10日から5月1日までの間に8つのフィットネスクラスを受講して、無料のTシャツを入手してください。

id owner_uid startDate endDate startTime endTime days recurrance
8ada0ceabd40d509c3fb38f2822a97de11bc6628 4/13/2012 4/13/2012 0:00:00NULLNULLなし2543a6ed0005ff6a0a7fc99cc2f9715d86804ecb0NULL NULL 12:30:00 2:00:00 2 3 7d219b64 4 f7c91e2f1daa9c696c22f5aa5736c167d1ba9f94 NULL NULL NULL NULL NULL NULL 5 262f06fb75645248162aa983f610ec7959a2011b NULL NULL NULL NULL NULL NULL 6 51f9f552ffc5fa4bc8b4e7f914fb22b3b0920c2e NULL NULL NULL NULL 6 51f9f552ffc5fa4bc8b4e7f914fb22b3b0920c2e NULL NULL NULL

コントローラフォルダに、次のコードを含むmain.phpという名前のファイルがあります。

...
function fitnessSchedule()
    {
        $this->config->set_item('url_suffix', '');
        $crud = new grocery_CRUD();

        $crud->set_model('schedule_model');
        $crud->set_table('tblFitnessClasses');
        $crud->join_table('tblFitnessClasses','tblFitnessClassDateTimes');
        $crud->columns('title','description','location','startDate','endDate','startTime', 'endTime', 'days', 'recurrance');
        $crud->display_as('title','Event')
             ->display_as('description','Description')
             ->display_as('location','Location')
             ->display_as('startDate','Start Date')
             ->display_as('endDate','End Date')
             ->display_as('startTime','Start Time')
             ->display_as('endTime','End Time');
        $crud->required_fields('title','location');
        $crud->set_subject('Event');              

        $output = $crud->render();
        $this->_example_output($output);    
    }

    function _example_output($output = null)    
    {
        $this->load->view('main_view', $output);    
    }
...

私のモデルフォルダにはこれがあります:

<?php
class schedule_model extends grocery_CRUD_Model
{
        function join_table($table1, $table2)
        {
         if($this->$table1 === null)
          return false;

         $select = "{$this->$table1}.*";
         $select .=",$table2.startDate, $table2.endDate, $table2.startTime, $table2.endTime, $table2.days, $table2.recurrence";

         if(!empty($this->relation))
          foreach($this->relation as $relation)
          {
           list($field_name , $related_table , $related_field_title) = $relation;
           $unique_join_name = $this->_unique_join_name($field_name);
           $unique_field_name = $this->_unique_field_name($field_name);

        if(strstr($related_field_title,'{'))
                $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
           else   
                $select .= ", $unique_join_name.$related_field_title as $unique_field_name";

           if($this->field_exists($related_field_title))
                $select .= ", {$this->$table1}.$related_field_title as '{$this->$table1}.$related_field_title'";
          }

         $this->db->select($select, false);


         $this->db->join('uid', '$table2.owner_uid = $table1.uid');

         $results = $this->db->get($this->$table1)->result();

         return $results;
        }

        /* function join_table($table1, $table2)
        {
                $this->db->select('$table1.*');
                $this->db->join('$table2','$table1.uid = $table2.owner_uid','left');
                $this->db->get('$table1');
         }*/
}
?>

このエラーが発生します:

致命的なエラー:234行目のC:\ xampp \ htdocs \ codeigniter \ application \ controllers\main.phpにある未定義のメソッドgrocery_CRUD::join_table()を呼び出します

私は基本的に、UID(uidからowner_uid)を介してtblFacilityHrsをtblFacilityHrsDateTimesと連結しようとしています。ユーザーがテーブルを編集するときに、イベントの名前/場所だけでなく、その時刻/日付なども編集できるように、両方のテーブルを一度に表示したいと思います。

参照:http ://www.grocerycrud.com/documentation/options_functions/set_model

4

3 に答える 3

3

私は同じ質問をしました、そして以下は私がした解決策です。

  1. 結合したいテーブルのmySQL結合ステートメントを使用してビューを作成します
  2. 状態($ cur_state = $ crud-> getState();)を探し、それが「list、ajaxlist、readまたはsuccess」であるかどうかを確認してから、$ crud-> set_table('VIEW_NAME');を設定します。また、主キーを設定します$ crud-> set_primary_key('KEY'、'VIEW_NAME');
  3. elseの部分では、テーブル名自体を使用して、操作の追加、編集に役立てます。

このソリューションは非常にうまく機能しています。

$crud = new grocery_CRUD();
$cur_state=$crud->getState();
$crud->set_subject('Patient Notes');        

/* Use the mySQL view to display the data with related tables */
if(($cur_state=="list") || ($cur_state=="ajaxlist") || ($cur_state=="read") ||     ($cur_state=="success"))     
{
   $crud->set_table('patientsnotes_vw');
   $crud->columns('noteID','Clinic_No','note','noteCreated','username');
   $crud->set_primary_key('noteID','patientsnotes_vw');             

   if($cur_state=="read")
   {
    $crud->unset_fields('noteCreatedBy','user_id','patientID');                      
       }
}
else
{
        /* Use the patient_note table itself for add/edit operation */
        $crud->set_table('patient_notes');
    $crud->columns('noteID','Clinic_No','note','noteCreated','username');
    $crud->required_fields('note');
    $crud->field_type('noteCreatedBy', 'hidden', $this->userID);
    $crud->field_type('patientID', 'hidden', 1);
    $crud->unset_add_fields('noteCreated');
    $crud->unset_edit_fields('noteCreated');        
 }

  $crud->display_as('username','Note Created by');
  $crud->display_as('noteCreated','Note Created at');       
  $output = $crud->render();
于 2013-11-18T17:39:21.987 に答える
2

このフォーラムスレッドで、web-johnnyは、この機能はまだ可能ではないと述べています。

これは、食料品のCRUDにまだこの機能がない1-1の関係です。それは、私が将来それをするのにどれだけの時間がかかるか、そして/またはそれまでに何か良い寄付があるかどうかに依存します。

この機能は非常に重要であり、実行するのも非常に複雑ですが、多くのユーザーにとって、この機能が登場するときに多くの時間を節約できると思います。

おそらく、web-johnnyが良い寄付であるとみなすものを提供すれば、彼はそれを実装するかもしれません。

于 2012-04-25T13:47:20.890 に答える
0

クラスgrocery_CRUD($ crud = new grocery_CRUD();)はフォルダーライブラリにローカライズされており、モデルにjoin_tableを実装します。

于 2012-07-06T17:46:03.377 に答える